[英]IP Camera access using OpenCV
下面給出的代碼用於使用OpenCV訪問Axis IP攝像機。 在運行程序時,它首先顯示“打開cap_ffmpeg_impl ...時出錯”,然后顯示找不到相機。
#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://IPADDRESS/video.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;
}
我哪里錯了?
當我嘗試使用公共IP攝像機顯示IP攝像機時,我遇到了類似的問題。 Opencv需要一些典型的URL來打開相機。從下面的代碼中嘗試URL。 這是對我有用的代碼。
int main(int, char**) {
cv::VideoCapture vcap;
cv::Mat image;
// This works on a D-Link CDS-932L
const std::string videoStreamAddress = "http://ID:PASSWORD@IPADDRESS:PORTNO/mjpeg.cgi?user=ID&password=ID:PASSWORD&channel=0&.mjpg";
//open the video stream and make sure it's opened
if(!vcap.open(videoStreamAddress)) {
std::cout << "Error opening video stream or file" << std::endl;
return -1;
}
for(;;) {
if(!vcap.read(image)) {
std::cout << "No frame" << std::endl;
cv::waitKey();
}
cv::imshow("Output Window", image);
if(cv::waitKey(1) >= 0) break;
}
}
按原樣復制此代碼並嘗試。
#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <iostream>
int main(int, char**) {
cv::VideoCapture vcap;
cv::Mat image;
// This works on a D-Link CDS-932L
const std::string videoStreamAddress = "http://USER:PWD@IPADDRESS:8088/mjpeg.cgi?user=USERNAME&password=PWD&channel=0&.mjpg";
//open the video stream and make sure it's opened
if(!vcap.open(videoStreamAddress)) {
std::cout << "Error opening video stream or file" << std::endl;
return -1;
}
for(;;) {
if(!vcap.read(image)) {
std::cout << "No frame" << std::endl;
cv::waitKey();
}
cv::imshow("Output Window", image);
if(cv::waitKey(1) >= 0) break;
}
}
以下適用於通過以太網電纜連接到計算機的Axis M1004-W:
/mjpg/video.mjpg
,我打賭你的相似之處。 您提供給OpenCV的地址應如下所示:
http://<USERNAME>:<PASSWORD>@<IP_ADDRESS>/<the value of src>
這就是我的樣子:
http://uname:login@192.168.0.0/mjpg/video.mjpg
我在您的代碼中輸入了我的地址,可以看到OpenCV窗口中的視頻流。
我在我的iphone上安裝了“Mini WebCam”應用程序並將其用作帶有“ http://192.168.1.103 ”的ip攝像頭作為它的地址。 另外我使用了這段代碼:
VideoCapture capture;
Mat image;
if (!capture.open("http://192.168.1.103/video.cgi?.mjpg")) {
cout << "Error opening video stream or file" << endl;
return -1;
}
....
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.