How to access an IP camera using OpenCV (C++ code) ? is there a way to access with OpenCv+vlc ? (windows 7)
Solution 1
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;
}
Solution 2
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
Solution 3
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
Daki Withanage
Updated on June 05, 2022Comments
-
Daki Withanage almost 2 years
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 about 10 yearsThank 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."888888:[email protected]:8081/cgi/mjpg/mjpg.cgi?.mjpg"; 2.rtsp://cam_address:554/live.sdp 3.888888:[email protected]:3001/… I am missing something when im using it with my camera.
-
Mayur about 10 years1. 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 about 10 yearsUsing VLC to access the video is a work-around if you are unable to ge t the video using opencv directly.
-
Daki Withanage about 10 yearsin 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 ?