If network camera dicconnect from Network, application got hanged

asked 2015-02-22 23:08:45 -0500

Hello Team,

My application is accessing network camera. it's working good and getting frame using below code:

#include "stdafx.h"
#include "cv.h"
#include "cxcore.h"
#include "highgui.h"
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>

IplImage* frame1 = cvCreateImage(cvSize(640,360),8,3);

int _tmain(int argc, _TCHAR* argv[])
{
    CvCapture* input = cvCreateFileCapture("rtsp://admin:12345@192.168.1.15:554/ch1-s1?tcp");

    if(input == NULL)
    {
        exit(1);
    }

    frame1 = cvQueryFrame(input);

    while(1)
    {
        if(input == NULL)
        {
            exit(1);
        }

        frame1 = cvQueryFrame(input);

        cvShowImage("frame1",frame1);
        cvWaitKey(20);
    }

    cvDestroyWindow("frame");

    return 0;
}

Now Problem is, while application is running and my network camera got disconnected from Network, application got hanged.

I debug the code and found that applicatiom hanged at statement "cvQueryFrame(input)".

Can anyone guide me how to overcome this problem ??

Appreciate your reply and thank you in advance

edit retag flag offensive close merge delete

Comments

2

The c-Interface (with cvQueryFrame instead of C++ with cv::QueryFrame) is outdated for years and is no longer maintained and will vanish with OpenCV 3.0. So please upgrade your code. And in the new interface you could try VideoCapture::read http://docs.opencv.org/modules/highgu...

FooBar gravatar imageFooBar ( 2015-02-23 01:46:32 -0500 )edit