- added PiCameraPipeline

- added Lasertrack
- picam_test uses PiCameraPipeline



git-svn-id: http://moon:8086/svn/software/trunk/projects/opencv@324 b431acfa-c32f-4a4a-93f1-934dc6c82436
This commit is contained in:
2016-10-19 14:59:21 +00:00
parent 5434b0a16e
commit 7b083ccd14
4 changed files with 609 additions and 40 deletions
+48 -40
View File
@@ -1,54 +1,62 @@
# import the necessary packages
from __future__ import print_function
from imutils.video import FPS
from picamera import PiCamera
from picamera import CircularIO
import imutils
import time
import cv2
from picamera import PiCamera
from piCameraPipeline import PiCameraPipeline
from piCameraPipeline.PiCameraPipeline import RgbProcess
from piCameraPipeline.PiCameraPipeline import RgbProcessorAdapter
class MyCameraIo(object):
def __init__(self, frameSize):
print("MyCameraIo")
self.frameSize = frameSize[0]*frameSize[1]
self.size = 0
self.frames = 0
self.fps = None
if ("__main__" == __name__):
import cv2
def writable(self):
return True
# Unit test with to threaded processors
class MyRgbProcess1(RgbProcess):
def __init__(self, resolution=(320, 240, 3), numEntries=2, next=None):
super(MyRgbProcess1, self).__init__(resolution, numEntries, next)
def write(self, data):
if self.size == 0:
self.fps = FPS().start()
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)
self.size += len(data)
self.frames += len(data)/(3*self.frameSize)
cv2.imshow('displayThread1', gray_blurred)
cv2.waitKey(1)
def size(self):
print("size")
return self.size
if self.next is not None:
self.next.write(cv2.cvtColor(gray_blurred,cv2.COLOR_GRAY2BGR))
def flush(self):
if self.size > 0:
self.fps.stop()
print("Recorded " + str(self.frames) + " frames (" + str(self.size) + " bytes)")
print("FPS = " + str(self.frames/self.fps.elapsed()))
class MyRgbProcess2(RgbProcess):
def __init__(self, resolution=(320, 240, 3), numEntries=2, next=None):
super(MyRgbProcess2, self).__init__(resolution, numEntries)
def process(self):
data = self.read(1.0)
if data is not None:
gray = cv2.cvtColor(data,cv2.COLOR_BGR2GRAY)
# initialize the camera and stream
camera = PiCamera()
camera.resolution = (320, 240)
camera.framerate = 90
# Canny edge detection
canny = cv2.Canny(gray, 100, 50)
cv2.imshow('displayThread2', canny)
cv2.waitKey(1)
myCameraIo = MyCameraIo(camera.resolution)
camera.start_recording(myCameraIo, format="bgr")
# initialize the camera and stream
camera = PiCamera()
camera.resolution = (320, 240)
camera.framerate = 60
frameDim = (camera.resolution[0], camera.resolution[1], 3)
myProcessor2 = MyRgbProcess2((240, 320, 3), 4)
myProcessor1 = MyRgbProcess1((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)
# 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()
# do a bit of cleanup
cv2.destroyAllWindows()
camera.close()