Ask Your Question
1

VideoCapure: uncompressed 16 bit video stream (Y16)

asked 2018-07-18 05:32:15 -0600

adrianf0 gravatar image

Setup:

  • Ubuntu 16.04 LTS
  • OpenCV-python version 3.4.1
  • $v4l2-ctl -d /dev/video3 --list-formats
        ioctl: VIDIOC_ENUM_FMT
        Index       : 0
        Type        : Video Capture
        Pixel Format: 'Y16 '
        Name        : 16-bit Greyscale
    

Using VideoCapture I get 3 channels array of uint8 instead of single channel uint16. I can't set the proper CAP_PROP_FORMAT. Thus, the read method returns also array of uint8. How to capture 16 bit video with OpenCV-python?

 >>> cam = cv2.VideoCapture("/dev/video3")
 >>> cam.get(cv2.CAP_PROP_FORMAT)
16.0 (cv2.CV_8UC3)
>>> cam.set(cv2.CAP_PROP_FORMAT,cv2.CV_16U)
VIDEOIO ERROR: V4L2: setting property #8 is not supported
True
>>> _, frame = cam.read()
>>> frame
array([[[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       ...,

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]],

       [[0, 0, 0],
        [0, 0, 0],
        [0, 0, 0],
        ...,
        [0, 0, 0],
        [0, 0, 0],
        [0, 0, 0]]], dtype=uint8)

edit retag flag offensive close merge delete

Comments

you could try one of those

berak gravatar imageberak ( 2018-07-18 05:39:28 -0600 )edit

@berak: Thank you for your reply.

There is no Y16 format there. Moreover, mode settings are not fully supported:

  >>> cam.get(cv2.CAP_PROP_MODE)
 540422489.0
 >>> cam.set(cv2.CAP_PROP_MODE, cv2.CAP_MODE_GRAY)
 VIDEOIO ERROR: V4L2: setting property #9 is not supported
 True
adrianf0 gravatar imageadrianf0 ( 2018-07-18 05:51:31 -0600 )edit

Opencv does not support Y16 format! You need to modify the source code to add Y16 support.

Balaji R gravatar imageBalaji R ( 2018-07-19 01:15:01 -0600 )edit

@Balaji , i don't think, that's true, see hereor here

berak gravatar imageberak ( 2018-07-19 01:21:38 -0600 )edit

@berak Thanks for the update! You are Right!!

Balaji R gravatar imageBalaji R ( 2018-07-19 01:36:35 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2018-07-20 09:17:24 -0600

adrianf0 gravatar image

After digging in the sources and commit logs (link), the solution is:

cam.set(cv2.CAP_PROP_CONVERT_RGB, False) 

PS. It's a bit silly I had to wait 2 days in order to share the answer I found myself...

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-07-18 05:32:15 -0600

Seen: 4,679 times

Last updated: Jul 20 '18