Hello Robin,
Thank you for the last message.
A question first ... Is it possible to have a longer time before the forum logoff me automatically ?
The reason is ... I write a long message ... and it take a long time ... when I was fast finished I try "Preview" ... but it was necessary to log me again, and then when I come back ... the message box was empty !
So I need now to rewrite all my message
Here the test script for setting the Start and End Position of the LED illumination (also only for the use with the QHY-174-GPS camera!).
The test user shall follow the following steps:
- Start SharpCap
- Select the QHY-174-GPS camera
- Set the camera parameters (bit, binning, exposure, ...)
- Switch-on the LED Illumination (the GPS receiver is not necessary for this test sequence)
- Click the "Auto Stretch" button
- Show "The Image Histogram"
- Click for the "FX Selection", move/modify the rectangle above the LED illumination area
- Start the Scripting console
- Copy the following code in the (lower part of the) console
- Start the script
The script does the assumption that a directory "C:\Temp\" exists. One image LED_test.png is saved in this directory.
On my desktop for the test today, I have large PCI 4.0 SSD M.2 ... also fast no delay for saving the image on the "disc".
In future, the image rectangle selection will "stay" in memory.
The script search for the transition between the "no-light" and "full-light" coming from the LED.
In future, I plane to solve a Fermi function for finding the middle intensity position and to show the curve in a nice graphic.
I will upload the future script in a separate message in the section of the QHY camera.
Please, note that part with the "dumpdata" and the "framehandler" is working.
I insert "dumpdata=False" after some delay time.
The problem is ... it is nice to have the value on the screen ... but I prefer to have it in a variable.
I try to copy the value ... but nothing happen. Haw can I have access to the data ?
In addition, please can you explain the meaning of both numbers ?
Code: Select all
# IronPython Pad. Write code snippets here and F5 to run. If code is selected, only selection is run.
import clr
clr.AddReference("System.Drawing")
clr.AddReference('System.Windows.Forms')
clr.AddReference('System.Drawing')
import sys
import time
import System.Drawing
import math
dumpdata = True
def framehandler(sender, args):
if (dumpdata):
cutout = args.Frame.CutROI(SharpCap.Transforms.SelectionRect)
print cutout.GetStats()
cutout.Release()
def evthandler(sender, args):
if (SharpCap.SelectedCamera != None):
SharpCap.SelectedCamera.FrameCaptured -= framehandler
def monitorFrames():
SharpCap.SelectedCamera.FrameCaptured += framehandler
SharpCap.CaptureEvent += evthandler
monitorFrames()
time.sleep(1)
dumpdata = False
print("GPS Calibration LED on/off : %s") % (SharpCap.SelectedCamera.Controls[21].Value)
print
Cal_End_Pos = SharpCap.SelectedCamera.Controls[19].Value
Cal_Start_Pos = SharpCap.SelectedCamera.Controls[20].Value
print SharpCap.SelectedCamera.Controls[18]
print("Calibration Start Pos Adjust: %i") % (Cal_Start_Pos)
print("Calibration End Pos Adjust : %i") % (Cal_End_Pos)
print("GPS Calibration LED on/off : %s") % (SharpCap.SelectedCamera.Controls[21].Value)
print("GPS Freq Stabilizazion : %s") % (SharpCap.SelectedCamera.Controls[22].Value)
print("GPS : %s") % (SharpCap.SelectedCamera.Controls[23].Value)
print
cloneRect = SharpCap.Transforms.SelectionRect
print("Rectangle Selection : "),
print cloneRect
print
#SharpCap.SelectedCamera.Controls.OutputFormat.Value = 'FITS files (*.fits)'
SharpCap.SelectedCamera.Controls.OutputFormat.Value = 'PNG files (*.png)'
def rect_average():
SharpCap.SelectedCamera.CaptureSingleFrameTo("c:\Temp\LED_test.png")
time.sleep(2)
bm = System.Drawing.Bitmap("c:\Temp\LED_test.png")
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(5,5)
sum += float(pixel.R)
# print("Pixel sum : %f") % (sum)
# print("Box average: %f") % (sum/nb_pixel)
bm.Dispose()
cloneBitmap.Dispose()
# return sum/nb_pixel
return math.floor(sum/1000)
def LED_cal_start_pos():
X.append(SharpCap.SelectedCamera.Controls[20].Value)
time.sleep(1)
box.append(rect_average())
temp.append((X[-1],box[-1]))
return
def LED_cal_start_pos_set(calvalue):
SharpCap.SelectedCamera.Controls[20].Value = int(calvalue)
X.append(SharpCap.SelectedCamera.Controls[20].Value)
time.sleep(1)
box.append(rect_average())
temp.append((X[-1],box[-1]))
return
def LED_cal_end_pos():
X.append(SharpCap.SelectedCamera.Controls[19].Value)
time.sleep(1)
box.append(rect_average())
temp.append((X[-1],box[-1]))
return
def LED_cal_end_pos_set(calvalue):
SharpCap.SelectedCamera.Controls[19].Value = int(calvalue)
X.append(SharpCap.SelectedCamera.Controls[19].Value)
time.sleep(1)
box.append(rect_average())
temp.append((X[-1],box[-1]))
return
'''
def Show_vector(V):
for i in range(len(V)):
print V[i]
return
'''
def Show_matrix(M):
for i in range(len(M)):
for j in range(len(M[0])):
print str(M[i][j]) + " ",
print
return
# *****************************************************************************
# LED Calibration Start Position Adjustment
box = []
X = []
temp = []
SharpCap.SelectedCamera.Controls[20].Value = Cal_Start_Pos
LED_cal_start_pos() # Initialise with the SharpCap start position
print("Cal Start Pos: %i") % Cal_Start_Pos
LED_cal_start_pos_set(Cal_Start_Pos * 1.1)
LED_cal_start_pos_set(Cal_Start_Pos * 0.9)
average_start = (min(box) + max(box)) / 2.0
print("Average"), average_start
cal_start = math.floor(math.log10(Cal_Start_Pos)) - 1
cal_start = 10**cal_start
LED_cal_start_pos_set(Cal_Start_Pos)
while (cal_start >= 1.0):
print cal_start
while True:
Cal_Start_Pos -= cal_start
LED_cal_start_pos_set(Cal_Start_Pos)
if (box[-1] < average_start):
Cal_Start_Pos = X[-1] + cal_start
break
cal_start = cal_start / 10
print
print("Measurement:")
print("StartPos: Intensity:")
Show_matrix(temp)
# END LED Calibration Start Position Adjustment
# *****************************************************************************
# *****************************************************************************
# LED Calibration End Position Adjustment
box = []
X = []
temp = []
SharpCap.SelectedCamera.Controls[19].Value = Cal_End_Pos
SharpCap.SelectedCamera.Controls[19].Value = Cal_End_Pos
LED_cal_end_pos() # Initialise with the SharpCap end position
print
print("Cal End Pos: %i") % Cal_End_Pos
LED_cal_end_pos_set(Cal_End_Pos * 0.9)
LED_cal_end_pos_set(Cal_End_Pos * 1.1)
average_end = (min(box) + max(box)) / 2.0
print("Average"), average_end
cal_end = math.floor(math.log10(Cal_End_Pos)) - 1
cal_end = 10**cal_end
LED_cal_end_pos_set(Cal_End_Pos)
while (cal_end >= 1.0):
print cal_end
while True:
Cal_End_Pos += cal_end
LED_cal_end_pos_set(Cal_End_Pos)
if (box[-1] < average_end):
Cal_End_Pos = X[-1] - cal_end
break
cal_end = cal_end / 10
print
print("Measurement:")
print("EndPos: Intensity:")
Show_matrix(temp)
# END LED Calibration End Position Adjustment
# *****************************************************************************
Concerning the IronPython inside SharpCap ... Is it possible to "exchange" the IronPython (2.7.9) with the IronLab (2.7.0.40) ?
In IronPython from SharpCap, it is not possible to load the dlls (ImportError: No module named NumpyDotNet).
Maybe it is possible to link some parts from IronLab in the IronPython (SC).
On the other side, I achieve to load the ALGLIB, MetNumerics and Math.Net libraries.
Each library has different way to represent the vector/matrices and different functions, but no library has a plot capability.
I begin to have a look in the .NET graphic function ... the problem is ... it exists maybe several 100 functions, but very few examples.
Regards,
Jean-Francois