From 903afdee3d750bb5c0c9ebab7888eb4e71d8096c Mon Sep 17 00:00:00 2001 From: gac-S_Changer Date: Thu, 17 Nov 2016 10:33:21 +0100 Subject: [PATCH] Script execution --- script/LedDetection.py | 58 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/script/LedDetection.py b/script/LedDetection.py index c961510..a497f9c 100644 --- a/script/LedDetection.py +++ b/script/LedDetection.py @@ -23,14 +23,14 @@ def detect_led(ip): roi_center = (2322, 1025) roi_radius = 1000 + + +""" def in_roi(x,y): global roi_center, roi_radius return math.hypot(x-roi_center[0], y-roi_center[1]) < roi_radius - -r=None def detect_led(ip): - global r aux = grayscale(ip, in_place=False) invert(aux) #subtract_background(aux) @@ -41,24 +41,68 @@ def detect_led(ip): output_image = "outlines", minCirc = 0.4 , maxCirc = 1.0) r=results - + print "\n" print r.getColumnHeadings() for row in range (r.counter): if in_roi(r.getValue("XM",row), r.getValue("YM",row)): print r.getRowAsString(row) else: - print >> sys.stderr, 'Invalid location:' + str(r.getValue("XM", row)) + ", " + str( r.getValue("YM", row)) - + #print >> sys.stderr, 'Invalid location:' + str(r.getValue("XM", row)) + ", " + str( r.getValue("YM", row)) + print >> sys.stderr, r.getRowAsString(row) return (results,output) - class MyFilter(Filter): def process(self, image, data): + ip = load_image(image) + (results,output) = detect_led(ip) + invert(output) + op_image(ip, output, "xor") + return ip.getBufferedImage() + +""" + + + +def in_roi(x,y): + return math.hypot(x-roi_radius, y-roi_radius) < roi_radius + + +def detect_led(ip): + global roi_center, roi_radius + aux = sub_image(ip, roi_center[0] - roi_radius, roi_center[1] - roi_radius, 2* roi_radius, 2*roi_radius) + grayscale(aux) + invert(aux) + #subtract_background(aux) + auto_threshold(aux) + binary_open(aux) + (results,output) = analyse_particles(aux, 800,4000, + fill_holes = True, exclude_edges = True,print_table=False, + output_image = "outlines", minCirc = 0.4 + , maxCirc = 1.0) + r=results + + print "\n" + print r.getColumnHeadings() + for row in range (r.counter): + if in_roi(r.getValue("XM",row), r.getValue("YM",row)): + print r.getRowAsString(row) + else: + #print >> sys.stderr, 'Invalid location:' + str(r.getValue("XM", row)) + ", " + str( r.getValue("YM", row)) + print >> sys.stderr, r.getRowAsString(row) + + return (results,output) + + +class MyFilter(Filter): + def process(self, image, data): + global roi_center, roi_radius ip = load_image(image) (results,output) = detect_led(ip) invert(output) #set_lut(output, outline_lut1[0], outline_lut1[1], outline_lut1[2]) #op_image(ip, output, "and") + output = pad_image(output, roi_center[0] - roi_radius, 0, roi_center[1] - roi_radius, 0) + op_image(ip, output, "xor") return ip.getBufferedImage() #return output.getBufferedImage()