Search code examples
c++opencvvideo-streamingvideo-captureip-camera

open cv ip camera c++, connection refused


I am trying to connect to my dlink ip camera using the following code:

//CvCapture *camera = cvCreateFileCapture("rtsp://admin:password123@192.168.2.74:554/0/1:1/main");
CvCapture *camera = cvCreateFileCapture("rtsp://admin:password123@192.168.2.74:554/ch1-s1");

if (camera == NULL) {

    printf("camera is null, aborting...");
    return;
}

printf("camera is not null\n");
fflush(stdout);
cvNamedWindow("img");

while (cvWaitKey(100) != 27) {

    IplImage *img = cvQueryFrame(camera);
    if (img == NULL) break;
    cvShowImage("img", img);
}

cvReleaseCapture(&camera);

and I am getting the following ERROR:

[tcp @ 0x103252d80] Connection to tcp://192.168.2.74:554?timeout=0 failed: Connection refused WARNING: Couldn't read movie file rtsp://admin:password123@192.168.2.74/ch1-s1

camera is null, aborting...Program ended with exit code: 0

any ideas appreciated, thanks


Solution

  • I think your problem is with the url.Try this:

    "http://USER:PWD@IPADDRESS:8088/mjpeg.cgi?user=USERNAME&password=PWD&channel=0&.mjpg";