gpt4 book ai didi

python - 如何将 picamera 视频帧转换为 openCV 对象

转载 作者:行者123 更新时间:2023-12-02 17:10:52 35 4
gpt4 key购买 nike

我正在尝试使用 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()

当我打印我的 numpy 数组时,它有内容,但解码后的图像对象总是没有。

所以我的问题是:如何正确使用 b 中提供的数据作为 cv2 框架?
我还是图像处理的新手...
提前感谢您的帮助!

最佳答案

参见 PiRGBAnalysis 的文档类(class)。

关于python - 如何将 picamera 视频帧转换为 openCV 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41984873/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com