- improved lasertrack
git-svn-id: http://moon:8086/svn/software/trunk/projects/opencv@331 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+20
-9
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user