Files
mxsc/script/LedDetectionProc.py
gac-S_Changer 195f79e94f Closedown
2017-06-22 14:44:32 +02:00

59 lines
1.7 KiB
Python

###################################################################################################
# Procedure to detect the puck light spots.
###################################################################################################
img.backgroundEnabled=False
led_ctrl1.write(0.0)
led_ctrl2.write(0.0)
time.sleep(0.1)
img.waitNext(100)
background = average_frames(5)
#img.backgroundImage=background.bufferedImage
#img.captureBackground(1,0)
#show_panel(img.backgroundImage)
#img.backgroundEnabled = True
led_ctrl1.write(0.40)
led_ctrl2.write(0.40)
time.sleep(0.1)
img.waitNext(100)
image = average_frames(5)
led_ctrl1.write(0.0)
led_ctrl2.write(0.0)
op_image(image, background, "subtract", float_result=True, in_place=True)
renderer = show_panel(image.getBufferedImage())
renderer.clearOverlays()
invert(image)
auto_threshold(image, method = "MaxEntropy") #Tested ok: MaxEntropy, Triangle, Yen
#binary_open(aux)
(r,output) = analyse_particles(image, 250,1000,
fill_holes = True, exclude_edges = False, print_table=False,
output_image = "outlines", minCirc = 0.3
, maxCirc = 1.0)
points = ""
npoints = 0
for row in range (r.counter):
if in_roi(r.getValue("XM",row), r.getValue("YM",row)):
#x, y = int(r.getValue("XM", row))+roi[0], int(r.getValue("YM", row))+roi[1]
x, y = int(r.getValue("XM", row)), int(r.getValue("YM", row))
points = points + " (" + str(x) + ", " + str(y) + ")"
npoints = npoints + 1
renderer.addOverlay(Crosshairs(Pen(java.awt.Color.MAGENTA), java.awt.Point(x,y), java.awt.Dimension(15,15)))
print str(npoints) + " - " + points
print r
#show_panel(output.getBufferedImage())
#img.backgroundEnabled=False