Videocapture SOMETIMES fail [closed]

asked 2017-04-16 08:59:07 -0600

alecs26 gravatar image

updated 2017-04-16 09:19:14 -0600

Hello (I am working with OpenCV 2.4.13 on Windows 8 with Qt5.7 MinGW),

I have a really weird problem with OpenCV. I try to grab video frames in a thread. It works very well all the time in release mode. In order to deploy my program, I copied the .exe in a folder and included all the dependencies with the .exe. I then built an installer with NSIS.

On several computers, the program works all the time. However, on two computers (Win 8 and Win 7),the videocapture sometimes fail. Sometimes I start the program and everything is fine. Other times, I start the program and all the frames are empty. In the latter case, the capture.open(0) returns 1 which is ok, but the frames are empty.

I tried this: When I get 10 empty frames, I release the video capture, reopen the camera and try to grab frame. But it does not work, the frames are always empty.

The point in common with these two computers is that they have AVG. There are more chances for the capture to fail when AVG is on. There is also more chances for the capture to fail when I run the program as an administrator.

I am working with OpenCV 2.4.13 on Windows 8 with Qt5.7 MinGW. Here is an exerpt of my code.

cv::VideoCapture capture;
int test1=capture.open(0); // This returns 1 so it's ok.
while(test1)
{
    capture >> frame;  
    if (!frame.empty())
    {
         //code here (when it fails it does not enter here)
    }
    else
    {
         //code here (when it fails it does enter here)
    }

Any ideas ????

Thank you so much,

Alex

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by alecs26
close date 2017-04-16 15:47:29.147803

Comments

SOMETIMES with lowercase is better sometimes

"There is also more chances for the capture to fail when I run the program as an administrator" Sure?

Do you use USB camera ?

Have you try to change exe priority ?

LBerger gravatar imageLBerger ( 2017-04-16 09:34:20 -0600 )edit

When I run as admin, it fails 70% of the time. Without admin, it fails 30% of the time. It might be a coincidence but it really seems a thing. Anyway, in both case it should work 100% of the time...

I just tried changing the .exe priority without difference.

Thanks,

Alex

alecs26 gravatar imagealecs26 ( 2017-04-16 09:54:35 -0600 )edit

Do you use USB camera ?

Is it exactly same driver for all pc?

LBerger gravatar imageLBerger ( 2017-04-16 10:05:03 -0600 )edit

Sorry yes it's a USB camera. I am not sure for the drivers, it was autoinstalled. Note that on the two faulty computers, the program works most of the time but sometimes (small caps :P) the videocapture fails.

alecs26 gravatar imagealecs26 ( 2017-04-16 10:10:05 -0600 )edit

When I have got problem like this one I try many things. idea :

  1. change webcam
  2. change usb port
  3. write a basic program without qt only opencv and win32gui
  4. unplugged ethernet cable
  5. change parameter in videocapture use CAP_DSHOW or CAP_MSMF (upper caps in Opencv :P)
LBerger gravatar imageLBerger ( 2017-04-16 10:23:59 -0600 )edit

Thank you. I wanted to try CAP_DSHOW or CAP_MSMF but they do not appear in the list. I only have CAP_SMART_CMD and CAP_ATA_ID_CMD. Are they only with OpenCV 3 ? I use OpenCV 2.4.13.

Also, what I want is to grab the images of each frame. Could I use something else than "VideoCapture" and "capture >> frame" ?

If there is another different way to grab the frames maybe it would help...

alecs26 gravatar imagealecs26 ( 2017-04-16 10:42:05 -0600 )edit

Also, there is something weird. When I run the program from the release folder (with the dll included) it works 100% of the time (I tried more than a hundred times). However, if I copy all the files to another folder, this is when the videocapture sometimes fail (50% of the time).

alecs26 gravatar imagealecs26 ( 2017-04-16 11:54:07 -0600 )edit

"However, if I copy all the files to another folder, this is when the videocapture sometimes fail (50% of the time)" Are you sure that you haven't got elsewhere older dll? check using depends.exe when configuration is wrong

LBerger gravatar imageLBerger ( 2017-04-16 12:22:03 -0600 )edit

That was a good idea. I used Process Explorer. However, both when it works or fail, the exact same dll are loaded.

alecs26 gravatar imagealecs26 ( 2017-04-16 12:58:49 -0600 )edit

If you have two dll in your system one in path and another in same folder of exe then dll loaded is second one (folder release) (see https://msdn.microsoft.com/en-us/libr...). If your program is ok with dll in same folder then these dll are goods.

"However, if I copy all the files to another folder" why do you mean exactly ?

LBerger gravatar imageLBerger ( 2017-04-16 13:41:33 -0600 )edit