- PiCameraPipeline: refactored interfaces

git-svn-id: http://moon:8086/svn/software/trunk/projects/opencv@332 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2016-10-22 08:22:07 +00:00
parent a572e2889e
commit a59fa57d9a
3 changed files with 75 additions and 57 deletions
+16 -11
View File
@@ -32,7 +32,7 @@ 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,
ap.add_argument("-e", "--with-ev3", type=str, default='off',
help="Framerate in frame/s")
ap.add_argument("-f", "--filename", type=str, default='piCamera',
help="Choose video source")
@@ -41,7 +41,7 @@ args = vars(ap.parse_args())
videoFile = args["filename"]
framerate = args["framerate"]
seconds = args["seconds"]
with_ev3 = args["with_ev3"]
with_ev3 = args["with_ev3"] == 'on'
class MyRgbProcess(RgbProcess):
def __init__(self, name, resolution=(320, 240, 3), numEntries=2, next=None, brick=None):
@@ -49,14 +49,13 @@ class MyRgbProcess(RgbProcess):
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 onFirstFrame(self):
self.sendBrick(0, 0)
def process(self):
def onLastFrame(self):
self.sendBrick(0, 0)
def onProcess(self):
data = self.read(1.0)
if data is not None:
gray = cv2.cvtColor(data,cv2.COLOR_BGR2GRAY)
@@ -108,13 +107,19 @@ class MyRgbProcess(RgbProcess):
if self.next is not None:
self.next.write(cv2.cvtColor(gray_blurred,cv2.COLOR_GRAY2BGR))
# Connect to brick
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)
if with_ev3:
# Connect to brick
with ev3.EV3() as brick:
videoSource = VideoSource(videoFile, (width,height,3), framerate)
proc = MyRgbProcess('MyRgbProcess', (240, 320, 3), 4, brick)
proc = MyRgbProcess('MyRgbProcess', (240, 320, 3), 4, brick=brick)
videoSource.processorAdd(proc)
videoSource.start()