2

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.

  • H.264/MJPEG video compression -G.722 audio compression
  • Frame rate 30fps /NTSC, 25fps/PAL
  • Resolution: 720P, D1, Half D1, CIF,
  • 1/3” SONY CCD, CMOS
  • Alarm I/O support motion detection, date, time, event trigger
  • Auto Day/Night
  • Two-way audio, broadcast system
  • RTSP, VLC(PS/TS) stream media protocol
  • Bit rate variable 32Kbps-4000Kbps
  • Multi-level user accessing with password protection
  • Free management software support 1-100 channels
Daki Withanage
  • 53
  • 1
  • 2
  • 8
  • Think. Which of the listed bullet points could possibly be relevant? Which parts of a communication stack did you leave out? – MSalters Feb 03 '14 at 11:26

3 Answers3

5

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;
}
Mayur
  • 789
  • 10
  • 37
  • Thank you so much for your reply sir, I am doing a Image processing project of human detection using my ip camera so to do that need to access Ip camera directly using opencv. I have used several C++ code projects to do that but always have a problem with access it using the IP adress, as an example = 1."http://888888:888888@192.168.1.19:8081/cgi/mjpg/mjpg.cgi?.mjpg"; 2.rtsp://cam_address:554/live.sdp 3.http://888888:888888@192.168.1.19:3001/video.cgi?resolution=640x360&req_fps=50&.mjpg I am missing something when im using it with my camera. – Daki Withanage Feb 05 '14 at 13:17
  • 1. Is your code working for USB camera ? If yes then your code works perfectly fine. 2. For IP camera I too struggled for couple of days, and finally could resolve it with the URL used in my code. 3. Opencv use a typical kind of url to access the IP camera, If the url is incorrect then you won't get the desired output. Just in case if you want to try different kind of url you kind find it from iSpy application. just configure your IP camera with iSpy and let the iSpy give you the URL and try to use one of the URL provide from iSpy. – Mayur Feb 06 '14 at 04:07
  • Using VLC to access the video is a work-around if you are unable to ge t the video using opencv directly. – Mayur Feb 06 '14 at 04:11
  • in iSpy i got several URLs. When i used the option add IP camera using wizard it asked me for a manufacture name which i dont have one for mine then next step it automatically scnaed my camera from LAN port and gave me URLs and but not in http everything in rtsp with VLC and FFMPEG. any clue about this ? – Daki Withanage Feb 08 '14 at 16:32
1

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

Community
  • 1
  • 1
Haris
  • 13,645
  • 12
  • 90
  • 121
1

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
Derzu
  • 7,011
  • 3
  • 57
  • 60