SC script in menu
Posted: Sun Sep 13, 2020 8:36 pm
Hello Robin,
I have a good version of my script for the LED calibration of the QHY-174-GPS camera.
My plan was to generate a "startup" script for a button on the menu bar.
It is not working ... but why ?
Here the script simplified (it should work with any camera). At the end I have 4 different comment areas ... the first 3 are working good, but the last one produce an error ... it simply freeze SharpCap ... so it is needed to stop SC with the Task Manager.
If the directory "C:\Temp\" does not exist, you can define a different directory.
The script save an image (LED_test.tif) and open it in a bitmap object, then the "rectangle selection" is used and the average is calculated.
I test the "menu-script" without the image saving ... it works.
I guess that something there is blocking SharpCap.
Alternative .. use the "framehandler"/evthandler"-"CutROI" command you send me in the past ... but I never achieve to finish the code.
Is it possible to "save" the settings of the IronPython console ?
It is necessary to set all the parameters again and again.
I do some experiment with the PythonLib.zip file ... I copy some additional files in the zip and it was possible to set the file reference "inside" the zip file. My idea was to "insert" some libraries for the direct use of NumpyDotNet, IronPlot or OxyPlot.
It was some success with the xalglib.dll. It was only a partially success with the IronPlot and OxyPlot ... if only 80% of the routine is recognised, then the missing 20% generates a blocking error. May be you have an idea how to exchange IronPython with IronLab ?
I try it ... I delete PythonLib.zip file and I generate a zip file from IronLab with the name PythonLib.zip.
The script console starts and I can do some basic operation ... but not more.
(note, after all these tests I delete SharpCap and I do a clear installation)
Regards,
Jean-Francois
I have a good version of my script for the LED calibration of the QHY-174-GPS camera.
My plan was to generate a "startup" script for a button on the menu bar.
It is not working ... but why ?
Here the script simplified (it should work with any camera). At the end I have 4 different comment areas ... the first 3 are working good, but the last one produce an error ... it simply freeze SharpCap ... so it is needed to stop SC with the Task Manager.
If the directory "C:\Temp\" does not exist, you can define a different directory.
The script save an image (LED_test.tif) and open it in a bitmap object, then the "rectangle selection" is used and the average is calculated.
I test the "menu-script" without the image saving ... it works.
I guess that something there is blocking SharpCap.
Alternative .. use the "framehandler"/evthandler"-"CutROI" command you send me in the past ... but I never achieve to finish the code.
Is it possible to "save" the settings of the IronPython console ?
It is necessary to set all the parameters again and again.
I do some experiment with the PythonLib.zip file ... I copy some additional files in the zip and it was possible to set the file reference "inside" the zip file. My idea was to "insert" some libraries for the direct use of NumpyDotNet, IronPlot or OxyPlot.
It was some success with the xalglib.dll. It was only a partially success with the IronPlot and OxyPlot ... if only 80% of the routine is recognised, then the missing 20% generates a blocking error. May be you have an idea how to exchange IronPython with IronLab ?
I try it ... I delete PythonLib.zip file and I generate a zip file from IronLab with the name PythonLib.zip.
The script console starts and I can do some basic operation ... but not more.
(note, after all these tests I delete SharpCap and I do a clear installation)
Regards,
Jean-Francois
Code: Select all
# *******************************************************************************************
#
# SharpCap script "Calibration_LED_menu.py"
# 2020/09/13 Jean-Francois Pittet
# Version: 1.0
#
# This script is to be placed in the list of the Startup script list:
# Menu "File", "SharpCap Settings", "Startup Scripts"
# The menu appears on the SharpCap window.
#
# The QHY-174-GPS camera hat to be connected with the LED switch-on.
# The GPS does not to be activated.
#
# In SharpCap the following actions have to be follow:
#
# - copy the script somewhere of the computer
# - start SharpCap
# - in "File" - "SharpCap Settings" - "Startup Scripts" - select this script
# - close SharpCap (the script will be loaded at the next start)
#
# - start SharpCap
# - connect QHY-174-GPS camera (I have no idea what happen if it is only the QHY-174 camera)
# - switch on the LED illumination (for the first test, no GPS is needed, the camera must be covered)
# - move the USB traffic or change the exposure time (so that SC fill the Start/End Pos values)
# - show "The Image Histogram" window
# - activate the "FX Selection Area" (for showing the red selection rectangle)
# - move and scale the selection rectangle above the most intense region of the LED illumination
# - start the script
#
# *******************************************************************************************
import clr
clr.AddReference("System.Drawing")
clr.AddReference("System.Windows.Forms")
clr.AddReference("System.Drawing")
import System
import time
import System.Drawing
import math
from array import array
from System.Windows.Forms import Application, Button, CheckBox, Form, FormStartPosition, Label, Panel, RadioButton, TextBox
from System.Drawing import Point
# (Begin) - Parameter to be changed by the user
temp_file = "c:\Temp\LED_test.tif" # Change the directory, if necessary
# (End) - Parameter to be changed by the user
cloneRect = SharpCap.Transforms.SelectionRect
expos_ms = SharpCap.SelectedCamera.Controls.Exposure.ExposureMs # Need to be sure that the last value is used
# *****************************************************************************
def LED_Calibration():
print("Dummy Calibration LED")
SharpCap.SelectedCamera.Controls.OutputFormat.Value = 'TIFF files (*.tif)'
SharpCap.SelectedCamera.CaptureSingleFrameTo(temp_file)
bm = System.Drawing.Bitmap(temp_file)
cloneBitmap = bm.Clone(cloneRect, bm.PixelFormat)
sum = 0.0
nb_pixel = cloneRect.Height * cloneRect.Width
for i in range(cloneRect.Height):
for j in range(cloneRect.Width):
pixel = cloneBitmap.GetPixel(j,i)
sum += float(pixel.R)
bm.Dispose()
cloneBitmap.Dispose()
print cloneRect
print sum/nb_pixel
# *****************************************************************************
class CalibrationLEDMenuForm(Form):
def __init__(self):
self.Text = "Calibration of the QHY-174 LED"
self.Width = 450
self.Height = 200
self.setupCheckButtons()
def setupCheckButtons(self):
self.Cal_LED = Button()
self.Cal_LED.Text = 'Calibration LED'
self.Cal_LED.Location = Point(25, 25)
self.Cal_LED.Click += self.calib_led
self.Cal_LED.AutoSize = True
self.button_Exit = Button()
self.button_Exit.Text = 'Exit'
self.button_Exit.Location = Point(175, 25)
self.button_Exit.Click += self.exit
self.AcceptButton = self.Cal_LED
self.CancelButton = self.button_Exit
self.Controls.Add(self.Cal_LED)
self.Controls.Add(self.button_Exit)
def calib_led(self, sender, event):
LED_Calibration()
def exit(self, sender, event):
print("Stop LED clalibration script")
self.Close()
# Try 1
#LED_Calibration()
# Try 1
# Try 2
#form = CalibrationLEDMenuForm()
#form.StartPosition = FormStartPosition.CenterScreen
#form.Show()
# Try 2
# Try 3
#def launch_form():
# form = CalibrationLEDMenuForm()
# form.StartPosition = FormStartPosition.CenterScreen
# form.Show()
#
#launch_form()
# Try 3
# Try 4
#def launch_form():
# form = CalibrationLEDMenuForm()
# form.StartPosition = FormStartPosition.CenterScreen
# form.Show()
#SharpCap.AddCustomButton("Cal_LED", None, "Calibration of the LED", launch_form)
# Try 4