- added VideoSource to piCameraPipeline git-svn-id: http://moon:8086/svn/software/trunk/projects/opencv@330 b431acfa-c32f-4a4a-93f1-934dc6c82436
63 lines
2.0 KiB
Python
Executable File
63 lines
2.0 KiB
Python
Executable File
# import the necessary packages
|
|
import time
|
|
from picamera import PiCamera
|
|
from piCameraPipeline import PiCameraPipeline
|
|
from piCameraPipeline.PiCameraPipeline import RgbProcess
|
|
from piCameraPipeline.PiCameraPipeline import RgbProcessorAdapter
|
|
|
|
if ("__main__" == __name__):
|
|
import cv2
|
|
|
|
# Unit test with to threaded processors
|
|
class MyRgbProcess1(RgbProcess):
|
|
def __init__(self, name, resolution=(320, 240, 3), numEntries=2, next=None):
|
|
super(MyRgbProcess1, self).__init__(name, resolution, numEntries, next)
|
|
|
|
def process(self):
|
|
data = self.read(1.0)
|
|
if data is not None:
|
|
gray = cv2.cvtColor(data,cv2.COLOR_BGR2GRAY)
|
|
gray_blurred = cv2.medianBlur(gray,5)
|
|
|
|
cv2.imshow('displayThread1', gray_blurred)
|
|
cv2.waitKey(1)
|
|
|
|
if self.next is not None:
|
|
self.next.write(cv2.cvtColor(gray_blurred,cv2.COLOR_GRAY2BGR))
|
|
|
|
class MyRgbProcess2(RgbProcess):
|
|
def __init__(self, name, resolution=(320, 240, 3), numEntries=2, next=None):
|
|
super(MyRgbProcess2, self).__init__(name, resolution, numEntries, next)
|
|
|
|
def process(self):
|
|
data = self.read(1.0)
|
|
if data is not None:
|
|
gray = cv2.cvtColor(data,cv2.COLOR_BGR2GRAY)
|
|
|
|
# Canny edge detection
|
|
canny = cv2.Canny(gray, 100, 50)
|
|
cv2.imshow('displayThread2', canny)
|
|
cv2.waitKey(1)
|
|
|
|
# initialize the camera and stream
|
|
camera = PiCamera()
|
|
camera.resolution = (320, 240)
|
|
camera.framerate = 60
|
|
frameDim = (camera.resolution[0], camera.resolution[1], 3)
|
|
myProcessor2 = MyRgbProcess2('Process 2', (240, 320, 3), 4)
|
|
myProcessor1 = MyRgbProcess1('Process 1', (240, 320, 3), 4, myProcessor2)
|
|
myRgbProcessorAdapter = RgbProcessorAdapter(frameDim)
|
|
myRgbProcessorAdapter.processorAdd(myProcessor1)
|
|
camera.start_recording(myRgbProcessorAdapter, format="bgr")
|
|
|
|
# allow the camera to warmup and start the FPS counter
|
|
print("[INFO] sampling frames from `picamera` module...")
|
|
time.sleep(10.0)
|
|
camera.stop_recording()
|
|
myProcessor1.stop()
|
|
|
|
# do a bit of cleanup
|
|
cv2.destroyAllWindows()
|
|
camera.close()
|
|
|