[英]C++/OpenCV Streaming Camera-Video/Images (MJPEG) from Socket into Browser (Windows 8.1)
[英]Streaming video from ip camera by opencv and c++
我正在尝试使用OpenCV代码从C ++访问网络摄像头流,但是它失败并显示无法打开流的错误。 将URL替换为0时,下面提到的代码将访问网络摄像头。可通过VLC和python代码访问同一摄像机。
#include <stdio.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <iostream>
int main(int, char**) {
VideoCapture cap("rtsp://admin:admin@10.11.18.185:554/cam/realmonitor?channel=1&subtype=0"); // open the video camera using http protocol with the URL specified
while (!cap.isOpened()) // if not success, exit program
{
cout << "cap not open" << endl;
continue;
//return -1;
}
Mat frame;
namedWindow("MyVideo", CV_WINDOW_AUTOSIZE);
while (1) {
cap.read(frame);
imshow("MyVideo", frame);
if (waitKey(30) == 27) //wait for 'esc' key press for 30ms. If 'esc' key is pressed, break loop
{
cout << "esc key is pressed by user" << endl;
exit(0);
}
}
}
VideoCapture库要求使用特定的格式集来接收视频流。
从保存的文件中读取文件时,我们在文件扩展名.mp4
, .avi
等中指定相同的名称。如果未指定此扩展名,VideoCapture将无法捕获帧。
尝试使用:
VideoCapture cap("rtsp://admin:admin@10.11.18.185:554/cam/realmonitor?channel=1&subtype=0/video?x.mjpeg");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.