Change videoCapture format to MJPEG
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;
}
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)
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.
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!
"the time to capture the frame to be as fast as possible" -- that's too broad. (and somewhat naive)
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 ?