Difference of VideoCapture in OpenCV 4.4.0 and OpenCV 3.4.0

when i use OpenCV3.4.0 to grab frame from camera, its parameter is set as follow:

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

capture.set(CV_CAP_PROP_FPS, 100);

capture.set(CV_CAP_PROP_FRAME_WIDTH, 640); 

capture.set(CV_CAP_PROP_FRAME_HEIGHT, 480);

it works well, and the fps is 100~200, that is enough for me.

But, when I use OpenCV 4.4.0 to use my yolov4 model, I set the parameter of VideoCapture as follow:

capture.set(CAP_PROP_FPS, 60);

capture.set(CAP_PROP_FRAME_WIDTH, 640); 

capture.set(CAP_PROP_FRAME_HEIGHT, 480);

capture.set(CAP_PROP_FOURCC, VideoWriter::fourcc('M', 'J', 'P', 'G'));

it can’t create pipe and can’t get any frame any more. SAD!

if I don’t set any parameter for VideoCapture(just use capture.open(2) and capture>>src ), it can works but its fps is only 5~8

Platform is Ubuntu 20.04, camera is just a common USB camera

how to solve it, or what may cause this problem?

this may be a problem of different backends. maybe the order of set() calls has an effect.

set the environment variable OPENCV_VIDEOIO_DEBUG=1, then run your program. OpenCV’s videoio module will be a little more talkative.

pass an apiPreference to the VideoCapture construction. pass CAP_GSTREAMER in both, then try CAP_V4L2 in both.