This commit is contained in:
gac-S_Changer
2018-05-22 16:07:56 +02:00
parent 5114bfaf3d
commit 05f982c86b
26 changed files with 595 additions and 221 deletions

View File

@@ -2,77 +2,93 @@
# Procedure to detect the puck light spots.
###################################################################################################
COVER_PRESENT = True
ROOM_TEMP = False
room_temp = False
number_frames = 10
number_backgrounds = 10
if get_exec_pars().source == CommandSource.ui:
PLOT = None
RENDERER = None
TEXT = None
if COVER_PRESENT:
cover_position = hexiposi.readback.take()
if (cover_position is None) or (cover_position == "Unknown"):
raise Exception("Unknown cover position")
else:
block_id = cover_position.upper()[0]
else:
block_id = None
print "Block id: ", block_id
number_frames = 5 if ROOM_TEMP else 10
number_backgrounds = 5 if ROOM_TEMP else 10
minimum_size = 150
maximum_size = 1500
min_circ = 0.2
threshold_method = "MaxEntropy" if room_temp else "Default" #Apparently good for LN2: Default, Intermodes, IsoData, Otsu
threshold_method = "MaxEntropy" if ROOM_TEMP else "Default" #Apparently good for LN2: Default, Intermodes, IsoData, Otsu
threshold_method,threshold_range = "Manual", (0, 215)
exclude_edges = True
led_latency = 0.5 #0.1
set_led_range(room_temp)
img.backgroundEnabled=False
set_led_state(False)
time.sleep(0.1)
img.waitNext(100)
time.sleep(led_latency)
img.waitNext(2000)
background = average_frames(number_backgrounds)
#img.backgroundImage=background.bufferedImage
#img.captureBackground(1,0)
#show_panel(img.backgroundImage)
#img.backgroundEnabled = True
set_led_state(True)
time.sleep(0.1)
img.waitNext(100)
time.sleep(led_latency)
img.waitNext(2000)
image = average_frames(number_frames)
set_led_state(False)
op_image(image, background, "subtract", float_result=True, in_place=True)
renderer = show_panel(image.getBufferedImage())
renderer.clearOverlays()
if RENDERER is None:
RENDERER = show_panel(image.getBufferedImage())
else:
RENDERER.setImage(None, image.getBufferedImage(), None)
RENDERER.clearOverlays()
invert(image)
auto_threshold(image, method = threshold_method) #Tested ok: MaxEntropy, Triangle, Yen
#renderer = show_panel(image.getBufferedImage())
#binary_open(aux)
if threshold_method == "Manual":
threshold(image, threshold_range[0], threshold_range[1])
else:
auto_threshold(image, method = threshold_method) #Tested ok: MaxEntropy, Triangle, Yen
(r,output) = analyse_particles(image, minimum_size,maximum_size,
fill_holes = True, exclude_edges = exclude_edges, print_table=False,
output_image = "outlines", minCirc = min_circ
, maxCirc = 1.0)
points = ""
npoints = 0
x=[]
y=[]
points = []
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.append(int(r.getValue("XM", row)))
y.append(int(r.getValue("YM", row)))
points = points + " (" + str(x[-1]) + ", " + str(y[-1]) + ")"
npoints = npoints + 1
renderer.addOverlay(Crosshairs(Pen(java.awt.Color.MAGENTA), java.awt.Point(x[-1],y[-1]), java.awt.Dimension(15,15)))
print str(npoints) + " - " + points
#print r
#print x
#print y
offset = int(math.sqrt(1000)/2)
cv = (min(x)-offset, min(y)-offset, max(x)+offset, max(y)+offset)
renderer.addOverlay(Rect(Pen(java.awt.Color.MAGENTA), java.awt.Point(cv[0], cv[1]), java.awt.Dimension(cv[2]-cv[0],cv[3]-cv[1])))
#show_panel(output.getBufferedImage())
#img.backgroundEnabled=False
x, y = int(r.getValue("XM", row)), int(r.getValue("YM", row))
cx, cy = img.getCalibration().convertToAbsoluteX(x), img.getCalibration().convertToAbsoluteY(y)
points.append([cx,cy])
RENDERER.addOverlay(Crosshairs(Pen(java.awt.Color.MAGENTA), java.awt.Point(x,y), java.awt.Dimension(15,15)))
#RENDERER.addOverlays(ovs)
clear_detection(block_id)
detect_pucks(points, block_id)
plot_base_plate(points, p=PLOT)
ret = get_puck_detection_dict(block_id)
if TEXT is not None:
TEXT.setText(str(ret))
set_return(ret)