- use ev3 brick

git-svn-id: http://moon:8086/svn/software/trunk/projects/opencv@326 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2016-10-19 15:58:24 +00:00
parent 77e322e3f8
commit 1d5ee3358c
+20 -15
View File
@@ -82,8 +82,9 @@ class VideoSource(RgbProcessorAdapter):
class MyRgbProcess(RgbProcess):
def __init__(self, resolution=(320, 240, 3), numEntries=2, next=None):
def __init__(self, brick, resolution=(320, 240, 3), numEntries=2, next=None):
super(MyRgbProcess, self).__init__(resolution, numEntries, next)
self.brick = brick
def process(self):
data = self.read(1.0)
@@ -100,6 +101,13 @@ class MyRgbProcess(RgbProcess):
if maxVal > 100*minVal:
img1_objects = cv2.rectangle(img1_objects,(x-5,y-5),(x+5,y+5),(0,0,255),2)
print(maxLoc)
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)
else:
# Contour approach
gray_blurred = cv2.GaussianBlur(gray,(5,5),0)
@@ -127,22 +135,19 @@ class MyRgbProcess(RgbProcess):
self.next.write(cv2.cvtColor(gray_blurred,cv2.COLOR_GRAY2BGR))
# Connect to brick
#with ev3.EV3() as brick:
with ev3.EV3() as brick:
# created a *threaded *video stream, allow the camera sensor to warmup,
# and start the FPS counter
videoSource = VideoSource(videoFile, (width,height,3), framerate)
proc = MyRgbProcess(brick, (240, 320, 3), 4)
videoSource.processorAdd(proc)
videoSource.start()
videoSource = VideoSource(videoFile, (width,height,3), framerate)
proc = MyRgbProcess((240, 320, 3), 4)
videoSource.processorAdd(proc)
videoSource.start()
print("[INFO] sampling THREADED frames from `" + videoFile + "` at " + str(framerate) + " frame/s")
time.sleep(seconds)
videoSource.stop()
proc.stop()
print("[INFO] sampling THREADED frames from `" + videoFile + "` at " + str(framerate) + " frame/s")
time.sleep(seconds)
videoSource.stop()
proc.stop()
# do a bit of cleanup
cv2.destroyAllWindows()
# do a bit of cleanup
cv2.destroyAllWindows()