Ask Your Question
0

RSTP video stream freezes the program while connection is lost..

asked 2016-11-03 09:13:34 -0600

PiMac gravatar image

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!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-12-30 07:29:09 -0600

PiMac gravatar image

The solution was simply to store returned boolen value from capturedVideo.read(cameraMat) method:

boolean tempBool = capturedVideo.read(cameraMat);

The freezing stopped. I hope it will help somebody else.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-11-03 09:13:34 -0600

Seen: 492 times

Last updated: Dec 30 '16