IP摄像头使用OpenCV访问
IP Camera access using OpenCV
下面给出的代码用于使用OPENCV访问轴IP摄像机。运行程序时,它首先显示"打开CAP_FFMPEG_IMPL中的错误",然后显示找不到相机。
#include <opencvcv.h>
#include <opencv2highguihighgui.hpp>
#include <opencv2imgprocimgproc.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;
}
}
通过以太网电缆连接到我的计算机的轴M1004-WENK:
- 在您选择的浏览器(我正在使用Chrome)中,导航到相机的IP地址。提供必要的凭据。
- 您应该看相机的直播流。右键单击视频流,然后选择"检查元素"(或在非铬浏览器中等效的元素)。
- 您应该看到一个称为SRC的变量 - 这是您可以在OpenCV中使用的变量直接访问相机。我的是
/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上安装了"迷你网络摄像头"应用程序,并将其用作IP摄像机,并将其用作" http://192.168.1.103"。此外,我使用了此代码:
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;
}
....
它有效。(http://192.168.1.103/video.cgi?.mjpg)
相关文章:
- C++中的openCV Mat访问冲突
- OpenCV C++:当垫子类型未知时无法访问垫子元素?
- OpenCV C++ 3 维垫数据访问错误值
- OpenCV Tracker 属性访问在 ARM 上因 SEGFAULT 而失败,但在 X86_64 中工作
- OpenCV 像素访问点与 at() - 不同的值
- 访问和更改基于另一个图像的像素颜色-opencv c++
- OpenCV 访问像素的颜色值
- 在 OpenCV 中使用 hog.compute(..) 进行访问冲突
- 如何在OpenCV Cuda(GpuMat)中访问像素
- 在 OpenCV 中访问具有多个线程的 Mat 是否线程安全?
- 使用OpenCV访问摄像头(通过GSTREAMER)
- systemd无法通过opencv访问摄像头
- IP摄像头使用OpenCV访问
- OpenCV:访问 5D Matrix 的元素
- 来自 Mat 的 OpenCV 访问元素
- opencv访问CV_32FC3 BGR CV::Mat的颜色元素
- OpenCV访问MAT对象中的RGB值
- 我如何使用OpenCV访问外部网络摄像头?
- 使用Mat OpenCV访问像素
- 如何在visual C++2010或2008中使用OpenCV 2.1访问ip摄像头(compro IP50W)