サイズ 640x480 の RAW YUYY422 フレームを Python3 OpenCV で RGB に変換しようとしています。OpenCV Docs と google のさまざまなソリューションを調べましたが、機能しないようです。
私が取得し続けるエラーは、次の変形です。
Before 614400 <class 'bytes'>
After 614400 <class 'numpy.ndarray'>
(614400,)
Traceback (most recent call last):
File "./capture.py", line 111, in <module>
cv2.cvtColor(dataBuffer, dataBuffer, cv2.COLOR_YUV2RGB_UYVY);
TypeError: only size-1 arrays can be converted to Python scalars
変換しようとしているコードは次のとおりです。
buf = v4l2_buffer()
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE
buf.memory = V4L2_MEMORY_MMAP
fcntl.ioctl(vd, VIDIOC_DQBUF, buf) # get image from the driver queue
mm = buffers[buf.index]
dataBuffer = mm.read()
print("Before",len(dataBuffer),type(dataBuffer))
dataBuffer = np.fromstring(dataBuffer, np.uint8)
print("After",len(dataBuffer),type(dataBuffer))
#dataBuffer = dataBuffer.reshape( 640, 480 )
print(dataBuffer.shape)
cv2.cvtColor(dataBuffer, dataBuffer, cv2.COLOR_YUV2RGB_UYVY);
dbusClient.run(dataBuffer)
mm.seek(0)
fcntl.ioctl(vd, VIDIOC_QBUF, buf) # requeue the buffer
この変換を行うにはどうすればよいですか? ありがとう。
更新:コメントごと:
for _ in range(50): # capture 50 frames
buf = v4l2_buffer()
buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE
buf.memory = V4L2_MEMORY_MMAP
fcntl.ioctl(vd, VIDIOC_DQBUF, buf) # get image from the driver queue
mm = buffers[buf.index]
dataBuffer = mm.read()
dataBuffer = np.fromstring(dataBuffer, dtype=np.uint8)
dataBuffer2 = cv2.cvtColor(dataBuffer, cv2.COLOR_BGR2YUV)
dbusClient.run(dataBuffer)
mm.seek(0)
fcntl.ioctl(vd, VIDIOC_QBUF, buf) # requeue the buffer
エラーが発生します:
OpenCV Error: Assertion failed (scn == 3 || scn == 4) in cvtColor, file /io/opencv/modules/imgproc/src/color.cpp, line 11144
Traceback (most recent call last):
File "./capture.py", line 106, in <module>
dataBuffer2 = cv2.cvtColor(dataBuffer, cv2.COLOR_BGR2YUV)
cv2.error: /io/opencv/modules/imgproc/src/color.cpp:11144: error: (-215) scn == 3 || scn == 4 in function cvtColor