Helo,
I have a fairly simple Java app which connects to few cameras through rstp stream, grabs the image and shows it in swing JFrame usnig OpenCV SwingWorker. My reconnect() method looks like this:
public void reconnect(String address) {
System.out.println("connecting...");
if (new ConnectionTester().pingHost(NETWORK_HOST, NETWORK_PORT, 50))
capturedVideo.open(address); // networkAddress
System.out.println("Still running");
if (!capturedVideo.isOpened()) {
System.out.println("Error while opening the camera!");
}
}
Because of a weak WiFi signal ( connection breaks) between the camera and my pc I sometimes get result like:
connecting...
Connection avaliable
and the program hangs while performing capturedVideo.open(address);
or on VideoCapture.read() method:
if (isOpened) {
capturedVideo.read(cameraMat);
Is there any way to avoid such situations by maybe waiting a set amount of time before stopping everything and reconnect again ?
Thanks!