- 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):
|
def __init__(self, name, resolution=(320, 240, 3), numEntries=2, next=None, brick=None):
|
||||||
super(MyRgbProcess, self).__init__(name, resolution, numEntries, next)
|
super(MyRgbProcess, self).__init__(name, resolution, numEntries, next)
|
||||||
self.brick = brick
|
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):
|
def process(self):
|
||||||
data = self.read(1.0)
|
data = self.read(1.0)
|
||||||
@@ -61,16 +69,19 @@ class MyRgbProcess(RgbProcess):
|
|||||||
x = maxLoc[0]
|
x = maxLoc[0]
|
||||||
y = maxLoc[1]
|
y = maxLoc[1]
|
||||||
if maxVal > 100*minVal:
|
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)
|
img1_objects = cv2.rectangle(img1_objects,(x-5,y-5),(x+5,y+5),(0,0,255),2)
|
||||||
print(maxLoc)
|
errorX = float(x)-160
|
||||||
if self.brick is not None:
|
errorY = float(y)-120
|
||||||
error = float(x)-160
|
self.sendBrick(errorX/2, errorY/2)
|
||||||
data = struct.pack("f", error/2)
|
# print(maxLoc)
|
||||||
ev3.system_command.write_mailbox(self.brick, 'ErrorX', data)
|
else:
|
||||||
error = float(y)-120
|
if self.isVisible:
|
||||||
data = struct.pack("f", error/2)
|
print ("NOT Visible")
|
||||||
ev3.system_command.write_mailbox(self.brick, 'ErrorY', data)
|
self.sendBrick(0, 0)
|
||||||
|
self.isVisible = False
|
||||||
else:
|
else:
|
||||||
# Contour approach
|
# Contour approach
|
||||||
gray_blurred = cv2.GaussianBlur(gray,(5,5),0)
|
gray_blurred = cv2.GaussianBlur(gray,(5,5),0)
|
||||||
|
|||||||
Reference in New Issue
Block a user