Daki Withanage
Daki Withanage

Reputation: 53

How to access an IP camera using OpenCV (C++ code) ? is there a way to access with OpenCv+vlc ? (windows 7)

I have tried many ways but some programs give me a gray color empty screen and another just exit the code detecting camera can not be accessed but couldn't find a solution even though program are successfully build in opencv.

I am using Microsoft Visual Studio 2010 with Opencv 2.4.3

These are the specification of my camera.

Upvotes: 2

Views: 13186

Answers (3)

Derzu
Derzu

Reputation: 7146

First you need to discovery the rtsp url of your ONVIF camera. Than you use the code at the @Mayur answered replacing the rtsp url by your rtsp url.

To discovery your rtsp url you can look for on this list: http://www.soleratec.com/support/rtsp/rtsp_listing

Or use some software that find it, I recommend the software onvif-device-tool (link) or the gsoap-onvif (link), both works on Linux, look at your terminal, the rtsp url will be there. After discovery the rtsp url I recommend to test it on vlc player (link), you can test using the menu option "opening network stream" or from command line:

vlc rtsp://your_url

Upvotes: 1

Mayur
Mayur

Reputation: 799

Here's the code which worked for me.

#include <opencv\cv.h>
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

int main()
{
    Mat frame;
    namedWindow("video", 1);
    VideoCapture cap("http://USERID:PASSWORD@IPADDRESS:PORT/video.cgi?resolution=640x360&req_fps=50&.mjpg");
    if(!cap.isOpened())
    {
        cout<<"Camera not found"<<endl;
        getchar();
        return -1;
    }
    while ( cap.isOpened() )
    {
        cap >> frame;
        if(frame.empty()) break;

        imshow("video", frame);
        if(waitKey(30) >= 0) break;
    }   
    return 0;
}

Upvotes: 5

Haris
Haris

Reputation: 14053

You can use OpenCV VideoCaptur class to open video streaming from web

Using

VideoCapture cap;
cap.open(192.168.1.180/?action=stream?dummy=param.mjpg);

Also refer the answer on below links

Ip-network-camera-access using OpenCV

OpenCV with Network Cameras

IP camera and OPENCV

Upvotes: 1

Related Questions