【问题标题】:Streaming video from ip camera by opencv and c++通过opencv和c ++从ip摄像头流式传输视频
【发布时间】:2018-05-09 06:52:03
【问题描述】:

我正在尝试使用 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);
        }
    }
}

【问题讨论】:

  • 您是否使用 VLC 通过 RTSP 流式传输您的相机?
  • 不,我只是在 VLC 中测试流式 url 是否正常工作。
  • consle 或 sth 中的任何错误消息?

标签: c++ opencv video-streaming rtsp ip-camera


【解决方案1】:

VideoCapture 库需要一组特定的格式来接收视频流。

从保存的文件中读取时,我们在文件扩展名中指定相同的名称-.mp4.avi 等。 如果不指定此扩展,VideoCapture 将无法捕获帧。

尝试使用:

VideoCapture cap("rtsp://admin:admin@10.11.18.185:554/cam/realmonitor?channel=1&amp;subtype=0/video?x.mjpeg");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多