问题
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