Ask Your Question

Revision history [back]

If network camera dicconnect from Network, application got hanged

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