git-svn-id: http://moon:8086/svn/software/trunk/projects/opencv@310 b431acfa-c32f-4a4a-93f1-934dc6c82436
60 lines
1.8 KiB
Python
Executable File
60 lines
1.8 KiB
Python
Executable File
# import the necessary packages
|
|
from __future__ import print_function
|
|
from PiVideoStream import PiVideoStream
|
|
from imutils.video import FPS
|
|
from picamera.array import PiRGBArray
|
|
from picamera import PiCamera
|
|
import numpy as np
|
|
import argparse
|
|
import imutils
|
|
import time
|
|
import cv2
|
|
|
|
# construct the argument parse and parse the arguments
|
|
ap = argparse.ArgumentParser()
|
|
ap.add_argument("-n", "--num-frames", type=int, default=100,
|
|
help="# of frames to loop over for FPS test")
|
|
ap.add_argument("-d", "--display", type=int, default=-1,
|
|
help="Whether or not frames should be displayed")
|
|
args = vars(ap.parse_args())
|
|
|
|
# created a *threaded *video stream, allow the camera sensor to warmup,
|
|
# and start the FPS counter
|
|
print("[INFO] sampling THREADED frames from `picamera` module...")
|
|
vs = PiVideoStream(resolution=(320,240), framerate=30).start()
|
|
time.sleep(2.0)
|
|
fps = FPS().start()
|
|
|
|
# loop over some frames...this time using the threaded stream
|
|
while fps._numFrames < args["num_frames"]:
|
|
# grab the frame from the threaded video stream
|
|
frame = vs.read()
|
|
|
|
hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)
|
|
h,s,v = cv2.split(hsv)
|
|
img = cv2.merge((h,s,v))
|
|
rgb = cv2.cvtColor(img, cv2.COLOR_HSV2BGR)
|
|
|
|
# check to see if the frame should be displayed to our screen
|
|
if args["display"] > 0:
|
|
if frame != None:
|
|
cv2.imshow("Frame", rgb)
|
|
key = cv2.waitKey(10) & 0xFF
|
|
else:
|
|
time.sleep(0.5)
|
|
|
|
# update the FPS counter
|
|
fps.update()
|
|
|
|
# stop the timer and display FPS information
|
|
fps.stop()
|
|
vs.stop()
|
|
print("[INFO] elasped time: {:.2f}".format(fps.elapsed()))
|
|
print("[INFO] approx. FPS: {:.2f}".format(fps.fps()))
|
|
print("[INFO] Camera : elasped time: {:.2f}".format(vs.getfps().elapsed()))
|
|
print("[INFO] Camera: approx. FPS: {:.2f}".format(vs.getfps().fps()))
|
|
|
|
# do a bit of cleanup
|
|
cv2.destroyAllWindows()
|
|
|