Ask Your Question
0

Timeout on VideoCapture.open(0)?

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

lobsterman gravatar image

I am calling VideoCapture.open(0) 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

Comments

Please try to use more recent version, like 3.4.3

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

1 answer

Sort by ยป oldest newest most voted
1

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

oyyablokov gravatar image

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

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

#define LIBAVFORMAT_INTERRUPT_OPEN_TIMEOUT_MS 30000
#define LIBAVFORMAT_INTERRUPT_READ_TIMEOUT_MS 30000

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:

cap.open(0, 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

Question Tools

1 follower

Stats

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

Seen: 7,428 times

Last updated: Nov 16 '18