Ask Your Question
0

Change videoCapture format to MJPEG

asked 2018-03-17 03:15:58 -0600

quentinboul gravatar image

Hi there,

I would like to get frames from my camera in the MJPEG format. I know for sure that my camera is able to use the MJPEG but when I try:

webcam.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));

I get:

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

Can you help?

Thanks!

Here is my code:

#include "opencv2/opencv.hpp"
#include <iostream>
#include <sstream>

using namespace std;
using namespace cv;

int main() {
    VideoCapture webcam;
    webcam.open(0);
    webcam.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));
    webcam.set(CV_CAP_PROP_FRAME_WIDTH, 1920);
    webcam.set(CV_CAP_PROP_FRAME_HEIGHT, 1080);

    Mat frame;
    webcam >> frame;         //get a new frame from camera
    imwrite("image.jpg", frame);
    return 0;
}
edit retag flag offensive close merge delete

Comments

it is not possible, to change the fourcc of a webcam, using VideoCapture.

why do you want that ?

the next thing you'd have to do would be: uncompress it again, else you can't use it in the code above.

you can try one of those , or to disable CAP_PROP_CONVERT_RGB (which will result in some kind of native YUV)

berak gravatar imageberak ( 2018-03-17 03:23:38 -0600 )edit

I have a See3Cam from e-con system. (https://www.e-consystems.com/4k-usb-c...) I really need my camera to take the picture as fast as possible and they say on their datasheet that the frame rate is higher when using MJPEG than UYVY . that's why I want to use MJPEG. But I don't know how to do that.

quentinboul gravatar imagequentinboul ( 2018-03-17 04:11:13 -0600 )edit
  • libv4l2 (or at least, opencv's wrapper) does not support it
  • getting images over the wire fast is one thing, but again, you'd need another (expensive) imdecode() call on the other side, to use the image
berak gravatar imageberak ( 2018-03-17 04:17:31 -0600 )edit

Do you mean that the time my camera would take to capture the frame wouldn't be different if I use MJPEG intead of UYVY? I don't really care about the time to get the images over the wire and the time my SoM takes to analyse the picture but I want the time to capture the frame to be as fast as possible. Thank you for your answers!

quentinboul gravatar imagequentinboul ( 2018-03-17 04:39:38 -0600 )edit

"the time to capture the frame to be as fast as possible" -- that's too broad. (and somewhat naive)

  • there's processing on the webcam (protocoll / compression)
  • then, there's transport over usb
  • then, there's cap_libv4l2, processing there, too (convert whatever we got to bgr, or not ?)
  • then, there's your app, what are you doing, what do you need ? (e.g., if all you need is grayscale, converting to/from bgr would be a waste, and you'd better just extract Y from YUV)


i guess, in the end, you have to profile / analyze all the steps involved, and take the optimal one for your application

P.S. did you consider to use libv4l directly, shortcutting the VideoCapture ?

berak gravatar imageberak ( 2018-03-17 04:50:19 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
0

answered 2019-08-23 09:28:59 -0600

Pls check whether the camera support the MJPEG format. To checking the use this below command $v4l2-ctl --list-formats. If support this format and set resolution and format by using the below command after open the video node

_CameraDevice.set(CV_CAP_PROP_FRAME_WIDTH, 640); _CameraDevice.set(CV_CAP_PROP_FRAME_HEIGHT, 480); _CameraDevice.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));

edit flag offensive delete link more
0

answered 2019-08-22 11:01:37 -0600

danide gravatar image

Hi, I think you might need a global shutter camera, it will send you a clean image.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2018-03-17 03:15:58 -0600

Seen: 14,745 times

Last updated: Aug 22 '19