- improved PiCameraPipeline (added names for procs, better thread mgmt)
- added VideoSource to piCameraPipeline git-svn-id: http://moon:8086/svn/software/trunk/projects/opencv@330 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
+5
-48
@@ -21,6 +21,7 @@ from picamera import PiCamera
|
||||
from piCameraPipeline import PiCameraPipeline
|
||||
from piCameraPipeline.PiCameraPipeline import RgbProcess
|
||||
from piCameraPipeline.PiCameraPipeline import RgbProcessorAdapter
|
||||
from piCameraPipeline.VideoSource import VideoSource
|
||||
|
||||
width = 320
|
||||
height = 240
|
||||
@@ -42,52 +43,9 @@ framerate = args["framerate"]
|
||||
seconds = args["seconds"]
|
||||
with_ev3 = args["with_ev3"]
|
||||
|
||||
class VideoSource(RgbProcessorAdapter):
|
||||
def __init__(self, fileName, resolution, framerate):
|
||||
super(VideoSource, self).__init__(resolution)
|
||||
self.fileName = fileName
|
||||
self.resolution = resolution
|
||||
self.framerate = framerate
|
||||
self.thread = None
|
||||
self.camera = None
|
||||
self.cancel = False
|
||||
if fileName == 'piCamera':
|
||||
self.camera = PiCamera()
|
||||
self.camera.resolution = (self.resolution[0], self.resolution[1])
|
||||
self.camera.framerate = self.framerate
|
||||
else:
|
||||
self.needRgbConversion = False
|
||||
self.thread = Thread(target=self.fileReadThread)
|
||||
|
||||
def fileReadThread(self):
|
||||
pass
|
||||
|
||||
def start(self):
|
||||
if self.thread is not None:
|
||||
self.thread.start()
|
||||
pass
|
||||
else:
|
||||
self.camera.start_recording(self, format="bgr")
|
||||
|
||||
def stop(self):
|
||||
if self.thread is not None:
|
||||
self.cancel = True
|
||||
self.thread.join()
|
||||
else:
|
||||
self.camera.stop_recording()
|
||||
|
||||
def fileReadThread(self):
|
||||
cap = cv2.VideoCapture(self.fileName)
|
||||
while not self.cancel:
|
||||
ret, frame = cap.read()
|
||||
if ret:
|
||||
self.write(frame)
|
||||
time.sleep(1.0/self.framerate)
|
||||
|
||||
|
||||
class MyRgbProcess(RgbProcess):
|
||||
def __init__(self, brick, resolution=(320, 240, 3), numEntries=2, next=None):
|
||||
super(MyRgbProcess, self).__init__(resolution, numEntries, next)
|
||||
def __init__(self, name, resolution=(320, 240, 3), numEntries=2, next=None, brick=None):
|
||||
super(MyRgbProcess, self).__init__(name, resolution, numEntries, next)
|
||||
self.brick = brick
|
||||
|
||||
def process(self):
|
||||
@@ -145,7 +103,7 @@ if with_ev3:
|
||||
with ev3.EV3() as brick:
|
||||
|
||||
videoSource = VideoSource(videoFile, (width,height,3), framerate)
|
||||
proc = MyRgbProcess(brick, (240, 320, 3), 4)
|
||||
proc = MyRgbProcess('MyRgbProcess', (240, 320, 3), 4, brick)
|
||||
videoSource.processorAdd(proc)
|
||||
videoSource.start()
|
||||
|
||||
@@ -155,14 +113,13 @@ if with_ev3:
|
||||
proc.stop()
|
||||
else:
|
||||
videoSource = VideoSource(videoFile, (width,height,3), framerate)
|
||||
proc = MyRgbProcess(None, (240, 320, 3), 4)
|
||||
proc = MyRgbProcess('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()
|
||||
|
||||
# do a bit of cleanup
|
||||
cv2.destroyAllWindows()
|
||||
|
||||
Reference in New Issue
Block a user