Reputation: 27956
I have the following method:
def _create_capture_object(self):
self._cap = cv2.VideoCapture(self._path_to_video)
self._width = self._cap.get(cv2.CAP_PROP_FRAME_WIDTH)
self._height = self._cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
self._frame_rate = self._cap.get(cv2.CAP_PROP_FPS)
self._frame_count = self._cap.get(cv2.CAP_PROP_FRAME_COUNT)
self._n_channels = self._cap.get(cv2.CAP_PROP_CHANNEL)
Everything works as expected, except
self._n_channels = self._cap.get(cv2.CAP_PROP_CHANNEL)
Which always returns 0.0
How can I get 1
in case of a gray-scale video, or 3
in case of a color video?
Upvotes: 0
Views: 1748
Reputation: 658
cv2.CAP_PROP_CHANNEL
attribute seems to
return 0 when querying a property that is not supported by the backend used by the VideoWriter instance.
Quoted from up to date documentation of opencv 4.3.
I believe the only way you can get the channel value is by capturing a frame then retriving the shape information of it.
EDIT #1: Thanks to @Dan Mašek I updated my answer corresponding to new documentation.
Upvotes: 3