- removed dup
git-svn-id: http://moon:8086/svn/software/trunk/projects/opencv@327 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+27
-11
@@ -31,13 +31,16 @@ ap.add_argument("-n", "--seconds", type=int, default=10,
|
||||
help="# of seconds to run")
|
||||
ap.add_argument("-r", "--framerate", type=int, default=30,
|
||||
help="Framerate in frame/s")
|
||||
ap.add_argument("-e", "--with-ev3", type=bool, default=False,
|
||||
help="Framerate in frame/s")
|
||||
ap.add_argument("-f", "--filename", type=str, default='piCamera',
|
||||
help="Whether or not frames should be displayed")
|
||||
help="Choose video source")
|
||||
args = vars(ap.parse_args())
|
||||
|
||||
videoFile = args["filename"]
|
||||
framerate = args["framerate"]
|
||||
seconds = args["seconds"]
|
||||
with_ev3 = args["with_ev3"]
|
||||
|
||||
class VideoSource(RgbProcessorAdapter):
|
||||
def __init__(self, fileName, resolution, framerate):
|
||||
@@ -101,12 +104,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)
|
||||
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)
|
||||
|
||||
else:
|
||||
# Contour approach
|
||||
@@ -135,10 +139,22 @@ class MyRgbProcess(RgbProcess):
|
||||
self.next.write(cv2.cvtColor(gray_blurred,cv2.COLOR_GRAY2BGR))
|
||||
|
||||
# Connect to brick
|
||||
with ev3.EV3() as brick:
|
||||
|
||||
if with_ev3:
|
||||
with ev3.EV3() as brick:
|
||||
|
||||
videoSource = VideoSource(videoFile, (width,height,3), framerate)
|
||||
proc = MyRgbProcess(brick, (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()
|
||||
else:
|
||||
videoSource = VideoSource(videoFile, (width,height,3), framerate)
|
||||
proc = MyRgbProcess(brick, (240, 320, 3), 4)
|
||||
proc = MyRgbProcess(None, (240, 320, 3), 4)
|
||||
videoSource.processorAdd(proc)
|
||||
videoSource.start()
|
||||
|
||||
@@ -147,7 +163,7 @@ with ev3.EV3() as brick:
|
||||
videoSource.stop()
|
||||
proc.stop()
|
||||
|
||||
# do a bit of cleanup
|
||||
cv2.destroyAllWindows()
|
||||
# do a bit of cleanup
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user