diff --git a/lasertrack.py b/lasertrack.py index 8fb84c4..30608ab 100755 --- a/lasertrack.py +++ b/lasertrack.py @@ -47,6 +47,14 @@ class MyRgbProcess(RgbProcess): def __init__(self, name, resolution=(320, 240, 3), numEntries=2, next=None, brick=None): super(MyRgbProcess, self).__init__(name, resolution, numEntries, next) self.brick = brick + self.isVisible = False + + def sendBrick(self, errorX, errorY): + if self.brick is not None: + data = struct.pack("f", errorX) + ev3.system_command.write_mailbox(self.brick, 'ErrorX', data) + data = struct.pack("f", errorY) + ev3.system_command.write_mailbox(self.brick, 'ErrorY', data) def process(self): data = self.read(1.0) @@ -61,16 +69,19 @@ class MyRgbProcess(RgbProcess): x = maxLoc[0] y = maxLoc[1] if maxVal > 100*minVal: + if not self.isVisible: + print ("Visible") + self.isVisible = True img1_objects = cv2.rectangle(img1_objects,(x-5,y-5),(x+5,y+5),(0,0,255),2) - print(maxLoc) - if self.brick is not None: - error = float(x)-160 - data = struct.pack("f", error/2) - ev3.system_command.write_mailbox(self.brick, 'ErrorX', data) - error = float(y)-120 - data = struct.pack("f", error/2) - ev3.system_command.write_mailbox(self.brick, 'ErrorY', data) - + errorX = float(x)-160 + errorY = float(y)-120 + self.sendBrick(errorX/2, errorY/2) +# print(maxLoc) + else: + if self.isVisible: + print ("NOT Visible") + self.sendBrick(0, 0) + self.isVisible = False else: # Contour approach gray_blurred = cv2.GaussianBlur(gray,(5,5),0)