Ask Your Question

Timeout on

asked 2014-11-09 17:48:28 -0500

lobsterman gravatar image

I am calling and everything works like a charm if I have a device at ID 0. Problem is if I don't have a openable device there, OpenCV will continue trying to establish a connection afaik - FOREVER. This occurs for example when I run the code on my laptop which has a facetime HD camera in the lid. if i run the computer from an external monitor and I have the lid down then it just hangs forever. As soon as I open the lid it springs to life. Is there any way to specify a timeout for trying? If it will never stop trying to connect then constructs like ...

if (!cap.isOpened()) // check if we succeeded

make no sense, because it will never report that it did not succeed. any solutions? I am using OpenCV 2.4.10 on Mac OSX 10.10 with Java 1.8.0_25. Thanks,

edit retag flag offensive close merge delete


Please try to use more recent version, like 3.4.3

mshabunin gravatar imagemshabunin ( 2018-11-16 14:21:02 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2018-11-16 10:35:24 -0500

oyyablokov gravatar image

updated 2018-11-16 10:44:09 -0500

First of all, if you use ffmpeg as a backend for VideoCapture, will actually return after some time (more specifically, the timeout is defined in ffmpeg somewhere in source):


If you are unsatisfied with these timeout values, I see two options. First - compile ffmpeg with changed constants and link against it, and second - try to use another backend (the list is here) like this:, cv::CAP_XIAPI); // or cv::CAP_<something else>

Update: this example is valid in C++, but maybe there is a similar workaround in Java.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2014-11-09 17:48:28 -0500

Seen: 1,707 times

Last updated: Nov 16 '18