Closed DapperTayra closed 5 years ago
The issue is that capture.get(CV_CAP_PROP_FOURCC) remains 2YUY no matter what I set. edit: YUY2
camera.set(CV_CAP_PROP_FOURCC, codec);
There is result of this operation. You should check it. Probably selection of FOURCC is not supported by this backend. Also "mjpeg" stream is useless for future processing - you would somehow decode it into RGB or other format.
cv::CAP_OPENCV_MJPEG
It is custom OpenCV implementation of mjpeg container for video files only. There is no support for cameras in this backend API.
Thank you for the information and the hint about the camera.set return code. Is the backend "DirectDraw" part of the OpenCV stack on Windows 10 or of Windows itself?
I've tried the code with another backend: v4l2 on Ubuntu 14.04. There I get 640x480@ 120fps. Could it be a limitation of my Windows 10 development environment, since VLC on Windows 10 plays and records 640x480@120fps?
Here is the Code for anyone who's interested in the Ubuntu solution, its basically the same as above. code.txt
@DapperTayra
Hi,
Thanks a lot for sharing your code, greatly appreciated. If this can help, I got -sort of- similar issue on Windows. Means I''ll follow this issue until it is fixed.
The differences with you are:
Disclaimer : is -DHAVE_VIDEOINPUT a good choice btw ?)
If I could obtain 30 fps in capture time on Windows, like it works already on Linux, the issue could be considered as fixed. I'm using .avi file format @ 30 fps, synch'ed with capture and everything is perfect on Linux already. But broken on Windows ... as usual :-/
In the code, I'm using something like : cv::VideoCapture cap(0+cv::CAP_DSHOW); int codec = CV_FOURCC('M','J','P','G'); //not 'm','j','p','2', but I'll test and add a comment about it later cap.set(CV_CAP_PROP_FOURCC, codec); cap.set(CV_CAP_PROP_FRAME_WIDTH, 1280.0); cap.set(CV_CAP_PROP_FRAME_HEIGHT, 720.0);
As you can see, I don't set the fps (it works well on Linux only on my side), because it gives unpredictable results on windows. e.g. 7,5 fps or whatever stupid value.
Waiting, I don't have the solution, but I got some suggestions:
can you try adding the following lines (just after cap.set frames dimensions):
cap.set(CAP_PROP_SETTINGS, 1); // this will open the webcam parameters box, and you'll be able to select whetever you need cap.set(CAP_PROP_BACKLIGHT, 1); // or 0 ? It is well known, Logitech does undocumented black magic around this property, and things can change a lot using the good option ...
In the case the choice is proposed, an you, e.g. uncheck the "Right Light" (in the case the options appears, not sure it will) and see whether things work better ?
do you use USB 3.x or USB 2.0 ? Is the webcam alone or is there another device on the same bus ?
did you try setting the fame size to 1280 x 720 ? Looks like the webcam auto-magicaly uses mjpeg in this case.
did you try setting the fps to 30 fps ?
your command line is very interesting : are fps float or integer btw ?
Last but not least: a big THANK YOU to the guys providing OpenCV !
After some tries, got it fixed. Can you try to remove the following line:
camera.set(CV_CAP_PROP_FPS, fps);
Looks like this line works on Linux only AND systematicaly breaks the webcam mode selection on windows (bug or feature ?)
FYI : I now can capture at MJPG 720p @30 fps on Windows, using whatever of the following webcams listed below:
@ebachard Thanks for the update. Could you try and see if you can get the C922 to run at 720p@60fps?
@DapperTayra Could you share your code that uses v4l2?
@carstenschwede
so far, all my tests failed, but I'll try to retry soon (my knowledge about MS Windows is limited, but I'm learning hard ;-)
The problem is I'm cross-compiling my software (search for miniDart on github) from Linux to Windows, and since Linuxmint does not upgrade often, I'm stuck with OpenCV 3.1.0 + an old version of mingw-64 (4.0.2 while the today's version, means 5.0.x is fixing High DPI and so on). That's why e.g. I can select any fps on Linux, and got only what Windows wants to provide (it depends on the ambiant light mostly).
I bet an up to date mingw-64 + Opencv 3.1.0 + recent ffmpeg should do it very well
Last but not least, I confirm we can obtain 720p @ ~34 to 40 fps (with good ambiant light) using the webcam mentioned below:
[EDIT] : it took me some time to understand, but when you connect the webcam without display the frames, you can obtain the promised 330fps at 480p, 120fps at 720p, and the 60fps at 1080p
(FYI, it was 16 days for delivery and ~ 95 euros per webcam -I ordered 2, to try stereo capture).
IMPORTANT : be less stupid than me, and order a distorsion corrected version ;-) (I'm dammed to learn fish eye filter since, to avoid distorsion)
Hi, all I use @DapperTayra code
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/videoio.hpp>
#include <ctime>
int main(int argc, char** argv)
{
cv::Mat in_frame;
int apiBackend = cv::CAP_DSHOW;
//int apiBackend = 2200;//cv::CAP_OPENCV_MJPEG; // this is not available in my built of OpenCV3
cv::VideoCapture camera(0+apiBackend);
if (!camera.isOpened())
{
std::cout << "Error! Camera not ready." << std::endl;
return -1;
}
int fps = 120;
int codec = CV_FOURCC('M','J','P','G');
camera.set(CV_CAP_PROP_FOURCC, codec);
camera.set(CV_CAP_PROP_FPS, fps);
camera.set(CV_CAP_PROP_FRAME_WIDTH, 1280);
camera.set(CV_CAP_PROP_FRAME_HEIGHT, 720);
int frame_counter = 0;
std::cout << cv::getBuildInformation() << std::endl;
std::cout << "opened video capure device at idx " << 0+cv::CAP_DSHOW << std::endl;
std::cout << "start reading" << std::endl;
std::clock_t begin = std::clock();
while (1)
{
if (frame_counter > 1000) break;
camera >> in_frame;
if (++frame_counter % 30 == 0)
{
std::clock_t end = std::clock();
double timePassed = double(end-begin);
begin = end;
if (timePassed > 0)
{
double zack = 30/(timePassed/1000);
std::cerr << "fps: " << zack << " of set " << fps << " fps in " << timePassed/1000 << "s @" << frame_counter << std::endl;
}
}
}
return 0;
}
If I use 720p (CV_CAP_PROP_FRAME_WIDTH = 1280, CV_CAP_PROP_FRAME_HEIGHT = 720), the FPS can be achieved 90, But if i use 480p(640 480) or (640360) my FPS will drop to 30. Why size reduction , FPS will fall, Does anyone know the answer?
// Windows, Qt // in my case...
VideoCapture cap; cap.open(0); cap.set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G')); // only this option, of course! // cap.set(CV_CAP_PROP_FPS, 120); //this line is not needed (for me) - fps is automatically set depending on the EXPOSURE cap.set(CV_CAP_PROP_FRAME_WIDTH, 320); cap.set(CV_CAP_PROP_FRAME_HEIGHT, 240); // only this resoluton could allow me to see the changed fps up to 99 (in my case with my cam) cap.set(CV_CAP_PROP_EXPOSURE, -6); // if -5 then 29fps; if -6 then 50fps; if <= -7 then fps can be // achieved 99 // cap.set (CAP_PROP_SETTINGS, 1); // uncomment this line and you can manually change all parameters at runtime and you can see how different parameters change fps in real time
// how to see your real fps? Mat image; namedWindow("window", CV_WINDOW_AUTOSIZE); clock_t t1 = clock(); clock_t t2 = clock(); int fps = 0; while (true) { cap >> image; t2 = clock(); if ((t2 - t1)>=1000) { t1 = t2; cout << fps<<" "; // or: cout << fps << endl; fps = 0; } else { ++fps; } imshow("window", image); // your monitor can show max 50 or 60 fps, but you need to work //with image - it is right? (varable image) if (waitKey(1000/480) == 27) // for ESC // 480 is ok number - I like this number:-))- //don't worry, but this number can not be smaller then 120 break; }
//Good luck to all of us!
@DapperTayra Sorry for hijacking the thread a bit, can you get the Brio to work at 4K resolution? (Don't care about framerate, just the snapshot resolution).
@ebachard As you managed to get MJPEG working, did you experience what is mentioned in https://github.com/opencv/opencv/issues/11324 ?
@PhilLab : I don't have Windows, and my time is very limited at the moment, because this is exams time currently (you're lucky, I randomly saw your question). To save your time, I'd suggest you to try by yourself : https://github.com/ebachard/miniDart/tree/master/testing_version ( what you have to do is just download / install / try the 0.7.0 on Windows 7+ and remove it at the end )
Last but not least, be aware I'm using 100% as graphic resolution. You'll need CTRL + Q to quit, just in case you are using the 125 or 150% HDPI resolution (windows size will be bigger than the screen). Without that, it's difficult to quit the application ...
@ebachard thanks. I tried it and saw the same problems mentioned in #11324
@DapperTayra : I now got a Logitech Brio 4K at hand, but cannot test under windows before some days, sorry.
Waiting, and if this can help you, after some tests, I can confirm the most important condition to obtain higher FPS is to have an USB 3.0 connector. Thus, I confirm I can capture at 60 FPS with the Logitech Brio, even at high resolutions on Linux using OpenCV (itself using V4l2 interface) BUT after I patched and built my own 4.15 kernel. See below for the link and the full explanation.
For the Linux users, I created a repository, collecting everything I found around UVC 1.5. For further information, please have a look at :
Of course, I'll add more Windows information asap. Stay tuned
Have the exact same issue as @DapperTayra (the original post). Same camera on windows with DSHOW and MJPG, only difference being python and opencv 4. I can't figure out how to solve it, and unfortunately I couldn't figure out a direct answer in this thread. I'm very interested to help out and solve this probelm :) I've tried great many things but none have worked. Any and all help or guidance would be appreciated
Usage questions should go to Users OpenCV Q/A forum: http://answers.opencv.org
OMG + WTF ! capture_->set(cv::CAP_PROPFOURCC, cv::VideoWriter::fourcc('m', 'j', 'p', 'g')); // <<<<<< works ! capture->set(cv::CAP_PROP_FOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G')); // does not work !
Correction, this works and provide 1920x1080@30 fps with C922
fourCCStringFromCode((int)capture_->get(cv::CAP_PROP_FOURCC), fourcc); std::cout << "cv::CAP_PROP_FOURCC = " << fourcc << std::endl; // displays' 2YUY'
capture_->set(cv::CAP_PROPFOURCC, cv::VideoWriter::fourcc('m', 'j', 'p', 'g')); capture->set(cv::CAP_PROPFOURCC, cv::VideoWriter::fourcc('M', 'J', 'P', 'G')); // this line only does not change the fourCC, need of the previous line too (soooo weird!) //capture->set(cv::CAP_PROPFPS, 60); capture->set(cv::CAP_PROP_FRAMEWIDTH, (double)cameraFrameWidth); capture_->set(cv::CAP_PROP_FRAMEHEIGHT, (double)cameraFrameHeight);
fourCCStringFromCode((int)capture_->get(cv::CAP_PROP_FOURCC), fourcc); std::cout << "cv::CAP_PROP_FOURCC = " << fourcc << std::endl; // displays 'GPJM' : at last !!
@swkzr you are a god! i've been struggling for weeks trying to get this Logitech C922 working... I've done exactly the order you wrote and magic it works!
Hi, I can confirm that it works on my PC* too. Thanks for the code ! But i have to declare VideoCapture as pointer otherwise it does not work with a reference... Weird.
*Windows 10, OpenCV 4.1.2 (installed with windows installer provided by OpenCV)
answers.opencv.org is down
Hello everybody,
my webcam Logitech BRIO supports MJPEG for higher resolutions or for higher frames per second. Sadly, I'm unable to set the VideoCapture backend to DirectShow and then to MJPG/mjp2/mjpa/mjpb in order to receive the compressed pictures from the camera (in 640x480@120fps).
I only get 30 FPS out of the thing using OpenCV3. With VLC the hardware manages to give me 120FPS.
A little help would be very much appreciated. Reading the sources of videoio did not help me any further than this failing code, answers.opencv.org has a solution only for Java and now its down anyways.
Gere is the code, the ffmpeg information dump and the OpenCV build information.
Code:
here are the supported modes of the Logitech BRIO webcam
this is the build information of my windows installation of OpenCV 3