- 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:
+20
-15
@@ -82,8 +82,9 @@ class VideoSource(RgbProcessorAdapter):
|
|||||||
|
|
||||||
|
|
||||||
class MyRgbProcess(RgbProcess):
|
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)
|
super(MyRgbProcess, self).__init__(resolution, numEntries, next)
|
||||||
|
self.brick = brick
|
||||||
|
|
||||||
def process(self):
|
def process(self):
|
||||||
data = self.read(1.0)
|
data = self.read(1.0)
|
||||||
@@ -100,6 +101,13 @@ class MyRgbProcess(RgbProcess):
|
|||||||
if maxVal > 100*minVal:
|
if maxVal > 100*minVal:
|
||||||
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)
|
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:
|
else:
|
||||||
# Contour approach
|
# Contour approach
|
||||||
gray_blurred = cv2.GaussianBlur(gray,(5,5),0)
|
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))
|
self.next.write(cv2.cvtColor(gray_blurred,cv2.COLOR_GRAY2BGR))
|
||||||
|
|
||||||
# Connect to brick
|
# Connect to brick
|
||||||
#with ev3.EV3() as brick:
|
with ev3.EV3() as brick:
|
||||||
|
|
||||||
# created a *threaded *video stream, allow the camera sensor to warmup,
|
videoSource = VideoSource(videoFile, (width,height,3), framerate)
|
||||||
# and start the FPS counter
|
proc = MyRgbProcess(brick, (240, 320, 3), 4)
|
||||||
|
videoSource.processorAdd(proc)
|
||||||
|
videoSource.start()
|
||||||
|
|
||||||
videoSource = VideoSource(videoFile, (width,height,3), framerate)
|
print("[INFO] sampling THREADED frames from `" + videoFile + "` at " + str(framerate) + " frame/s")
|
||||||
proc = MyRgbProcess((240, 320, 3), 4)
|
time.sleep(seconds)
|
||||||
videoSource.processorAdd(proc)
|
videoSource.stop()
|
||||||
videoSource.start()
|
proc.stop()
|
||||||
|
|
||||||
print("[INFO] sampling THREADED frames from `" + videoFile + "` at " + str(framerate) + " frame/s")
|
# do a bit of cleanup
|
||||||
time.sleep(seconds)
|
cv2.destroyAllWindows()
|
||||||
videoSource.stop()
|
|
||||||
proc.stop()
|
|
||||||
|
|
||||||
# do a bit of cleanup
|
|
||||||
cv2.destroyAllWindows()
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user