我想用opencv打开树莓派的摄像头,在网上找到了如下代码
# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))
# allow the camera to warmup
time.sleep(0.1)
# capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
# grab the raw NumPy array representing the image, then initialize the timestamp
# and occupied/unoccupied text
image = frame.array
# show the frame
cv2.imshow("Frame", image)
key = cv2.waitKey(1) & 0xFF
# clear the stream in preparation for the next frame
rawCapture.truncate(0)
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
结果是有图像显示但视频十分不流畅,求大神解惑!!
另外我用picamera模块调用摄像头实时显示时,没有任何结果,使用代码如下:
[code]import picamera
import picamera.array
import time
with picamera.PiCamera() as camera:
camera.resolution = (1920,1080)
camera.framerate = 30
print "start preview direct from GPU"
camera.start_preview() # the start_preview() function
time.sleep(10)
print "end preview"
求大神解惑,感激不尽!!!
# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))
# allow the camera to warmup
time.sleep(0.1)
# capture frames from the camera
for frame in camera.capture_continuous(rawCapture, format="bgr", use_video_port=True):
# grab the raw NumPy array representing the image, then initialize the timestamp
# and occupied/unoccupied text
image = frame.array
# show the frame
cv2.imshow("Frame", image)
key = cv2.waitKey(1) & 0xFF
# clear the stream in preparation for the next frame
rawCapture.truncate(0)
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
结果是有图像显示但视频十分不流畅,求大神解惑!!
另外我用picamera模块调用摄像头实时显示时,没有任何结果,使用代码如下:
[code]import picamera
import picamera.array
import time
with picamera.PiCamera() as camera:
camera.resolution = (1920,1080)
camera.framerate = 30
print "start preview direct from GPU"
camera.start_preview() # the start_preview() function
time.sleep(10)
print "end preview"
求大神解惑,感激不尽!!!