What does disabling `CV_CAP_PROP_CONVERT_RGB` do?

放肆的年华 提交于 2021-02-08 07:28:37

问题


I'm attempting to get raw camera output with opencv. If I read an image normally I get a 640x480x3 image:

>>> import cv2
>>> cap = cv2.VideoCapture(2)
>>> _, im = cap.read()
>>> im.shape
(480, 640, 3)

If I disable cv2.CAP_PROP_CONVERT_RGB then I get a strangely sized array, the end of which is always zeros:

>>> cap.set(cv2.CAP_PROP_CONVERT_RGB, False)
True
>>> _, im = cap.read()
>>> im.shape
(1, 614400)
>>> cv2.imshow('im', im.reshape((960, 640))); cv2.waitKey(0)

The resulting 'image' is:

What do I do with this data to get an actual image from it?


回答1:


From videoio.hpp:

CAP_PROP_CONVERT_RGB =16, //!< Boolean flags indicating whether images should be converted to RGB.

For your example, you need to decode the 1D data.

cv2.imshow('im', cv2.imdecode(im,-1))


来源:https://stackoverflow.com/questions/46396711/what-does-disabling-cv-cap-prop-convert-rgb-do

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!