我正在使用树莓来简单地显示视频(就目前来说)。为此,我必须使用opencv(cv2)。我尝试了很多解决方案,但现在我想使用Picamera库捕获视频。 我会告诉你我的代码:使用opencv + picamera stream捕获视频与覆盆子IO
import io
import time
import picamera
import cv2
import numpy as np
# Create the in-memory stream
stream = io.BytesIO()
with picamera.PiCamera() as camera:
while True:
camera.capture(stream, format='jpeg')
# Construct a numpy array from the stream
data = np.fromstring(stream.getvalue(), dtype=np.uint8)
# "Decode" the image from the array, preserving colour
image = cv2.imdecode(data, 1)
cv2.imshow('frame', image)
这是你可以看到很简单,但它不工作。事实上,它并不能打开窗户。 我想再现下一个,它完美的作品的行为:
#import numpy as np
import cv2
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()
任何想法?
似乎cv2.imshow('框架',图像)不能正常工作。 – giogix 2014-10-02 21:10:15
您忘记了cv2.waitKey()行。它不会没有工作。 – berak 2014-10-03 06:30:10
真的吗? ...为什么? ...是不是cv2.waitKey()只是从键盘获取命令? – giogix 2014-10-03 07:55:05