[英]How to convert picamera video frame to openCV object
I'm trying to record a video with the python raspberry camera module and then convert each frame to a openCV frame with no success: 我正在尝试使用python树莓派摄像头模块录制视频,然后将每个帧转换为openCV帧,但没有成功:
import time
import picamera
import cv2
import numpy as np
class BroadcastOutput(object):
def __init__(self, camera):
return
def write(self, b):
#create numpy array from b
data = np.fromstring(b, dtype=np.uint8)
#doesn't work with reshape either
#data = np.fromstring(b, dtype=np.uint8).reshape(320, 280, 3)
#enconde as image
image = cv2.imdecode(data, 1)
#test if is valid cv2 object -> fails
cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
def flush(self):
print('Waiting for background conversion process to exit')
#camera setup and start
with picamera.PiCamera() as camera:
camera.resolution = (320, 280)
camera.framerate = 24
time.sleep(2) # camera warm-up time
print('Initializing broadcast thread')
output = BroadcastOutput(camera)
print('Starting recording')
camera.start_recording(output, 'bgr')
try:
while True:
camera.wait_recording(1)
except KeyboardInterrupt:
pass
finally:
print('Stopping recording')
camera.stop_recording()
When i print my numpy array it has content, the image object after decode however is always none. 当我打印我的numpy数组时,它具有内容,但是解码后的图像对象始终为空。
So my question: How do i correctly use the provided data in b as an cv2 frame? 所以我的问题是:我如何正确使用b中提供的数据作为cv2框架? I'm still new to image processing... Thanks for any help in advance! 我还是图像处理的新手...预先感谢您的帮助!
请参阅PiRGBAnalysis类的文档。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.