Ask Your Question
0

Changing pixel format (YUYV to MJPG) when capturing from webcam?

asked 2014-09-13 06:55:36 -0500

bernizt gravatar image

updated 2014-09-13 10:28:15 -0500

Hello,

I am having problems when capturing from a logitech c270 using OpenCV 2.4.2. The only working resolution is 800 x 600, as OpenCV also sets pixel format to MJPG. When the application is running, the command v4l2-ctl -V prints:

Format Video Capture:
    Width/Height  : 800/600
    Pixel Format  : 'MJPG'
    Field         : None
    Bytes per Line: 0
    Size Image    : 816000
    Colorspace    : SRGB

With any other resolution the application freezes and v4l2-ctl -V prints (resolution matches the selected one):

Format Video Capture:
    Width/Height  : 640/480
    Pixel Format  : 'YUYV'
    Field         : None
    Bytes per Line: 1280
    Size Image    : 614400
    Colorspace    : SRGB

The following commands work:

cap.set(CV_CAP_PROP_FRAME_WIDTH,800); cap.set(CV_CAP_PROP_FRAME_HEIGHT,600);

But trying to change any other parameter with the set commands throws a:

HIGHGUI ERROR: V4L: Property <unknown property string>(5) not supported by device

I have been searching for a solution but I have had no luck. If I could capture, for example, 640 * 480 in MJPG (which v4l2-ctl --list-formats-ext shows as supported by my camera) would OpenCV work? How can I change pixel format inside OpenCV?

Edit: The following command v4l2-ctl --set-fmt-video=width=640,height=480,pixelformat=1 gives the expected result, I want to do the same action in OpenCV.

Thank you very much,


USB Camera: Logitech c270 Resolutions: various Pixel formats: YUYV and MJPG (checked with the command v4l2-ctl --list-formats-ext)

Beaglebone OpenCV 2.4.2 (default version in Angstrom Distribution)

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-07-14 07:38:02 -0500

Have you tried this:

capture = cv2.VideoCapture(self.cam_id, cv2.CAP_V4L2)
capture.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter_fourcc('M', 'J', 'P', 'G'))

And also building from source with -D WITH_V4L=ON and -D WITH_LIBV4L=ON.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-09-13 06:55:36 -0500

Seen: 10,896 times

Last updated: Jul 14