欢迎来到代码驿站!

当前位置:首页 >

如何基于C++解决RTSP取流报错问题

时间:2020-08-14 12:00:09|栏目:|点击:

使用g++ opencv_demo.cpp -o test 会报以下错误

这是我的代码:

#include <string>
#include <iostream>
#include <time.h>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
#include <opencv2/videoio/videoio.hpp>
#include <opencv2/imgproc/imgproc_c.h>
//#pragma comment(lib, "")


using namespace std;
using namespace cv;

void Video_to_Image(Mat& frame);

int main()
{
  //string filename = "Wildlife.wmv";
  string filename = "rtsp://admin:abc.1234@10.12.18.131:554";
  Mat frame;
  VideoCapture cap;
  cap.open(filename);
  if (!cap.isOpened()) {
    cerr << "ERROR! Unable to open camera\n";
    return -1;
  }

  //--- GRAB AND WRITE LOOP
  cout << "Start grabbing" << endl
    << "Press any key to terminate" << endl;
  time_t start_time = time(NULL);
  for (;;)
  {
    // wait for a new frame from camera and store it into 'frame'
    cap.read(frame);
    // check if we succeeded
    if (frame.empty()) {
      cerr << "ERROR! blank frame grabbed\n";
      break;
    }
    // show live and wait for a key with timeout long enough to show images
    imshow("Live", frame);

    // 每隔2s保存图片
    time_t end_time = time(NULL);
    if ((end_time - start_time) >=2)
    {
      cout << "2s capture" << endl;
      Video_to_Image(frame);
      start_time = time(NULL);
    }

    if (waitKey(5) >= 0)
      break;
  }
  cap.release();

  return 0;
}

void Video_to_Image(Mat& frame)
{

  char image_name[PATH_MAX];
  sprintf(image_name, "%s%s", "test_image", ".jpg");
  imwrite(image_name, frame);

}

解决方案:

g++ `pkg-config opencv --cflags` opencv_demo.cpp -o test `pkg-config opencv --libs`

上一篇:ASP.NET Core 奇淫技巧之伪属性注入的实现

栏    目:

下一篇:R语言ggplot2边框背景去除的实现

本文标题:如何基于C++解决RTSP取流报错问题

本文地址:http://www.codeinn.net/misctech/3542.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有