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

使用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`

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。

(0)

相关推荐

  • C++使用MySQL-Connector/C++连接MySQL出现LNK2019错误的解决方法

    使用vs2015开发c++win32项目时,用MySQL-Connector/c++连接MySQL时总是出现error: LNK2019错误 错误原因可能为: 1.缺少相应的库文件: 2.项目平台和所引用的第三方SDK不一致,即32bit对应引用了64bit,64bit对应引用了32bit. 解决方法: 1.检查项目中是否缺少某些库文件: 2.如果没有缺少库文件检查项目的属性,看看"平台"是不是和所引用的MySQL-Connector/c++不一致,即平台为Win32,所引用的MySQ

  • 解决安装mysqlclient的时候出现Microsoft Visual C++ 14.0 is required报错

    在安装mysqlclient的时候出现了以下报错: 解决办法: 1.到提示网址:https://visualstudio.microsoft.com/download/里面下载对应VC++版本安装后继续安装mysqlclient.但是本人没有找到对应文件,故不再过多赘述,这里说下第二种方法. 2.1到https://www.lfd.uci.edu/~gohlke/pythonlibs/找到mysqlclient编译包下载对应版本: 注:前面代表python版本,后面的win代表Python位数.

  • Python3安装模块报错Microsoft Visual C++ 14.0 is required的解决方法

    问题一:安装模块时出现报错 Microsoft Visual C++ 14.0 is required,也下载安装了运行库依然还是这个错误 解决: 1.打开Unofficial Windows Binaries for Python Extension Packages(http://www.lfd.uci.edu/~gohlke/pythonlibs/),这里面有很多封装好的Python模块的运行环境 2.找到所需要下载的模块文件对应版本进行下载. 如,需要下载Pymssql,本机安装是32位

  • 解决VC++编译报错error C2248的方案

    在使用诸如:CArray或是 CList等类时,经常会出现此错误 此错误的原因是由于自定义的类的数组项时 有一个操作如  Add()  在这个操作中,实际上需要一个 = 操作,但是这个 =操作在 自定义类中没有实现,于是,程序自动去它的parent 类 也就是 CObject 类去找,但是却找到个这个类的 = 是一个 private  于是就报了这个错误. 知道了原因解决方法自然就有了,那就是在自定义类中 重载操作符 =   重载后 这个错误就没有了. class COptRect : publ

  • 解决启动MongoDB错误:error while loading shared libraries: libstdc++.so.6:cannot open shared object file:

    启动MongoDB时,提示: error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory [root@SnsWeb ~]# /usr/local/mongodb/bin/mongod --dbpath=/usr/local/mongodb/data --logpath /usr/local/mongodb/logs/mongodb.l

  • 解决Scrapy安装错误:Microsoft Visual C++ 14.0 is required...

    问题描述 当前环境win10,python_3.6.1,64位. 在windows下,在dos中运行pip install Scrapy报错: building 'twisted.test.raiser' extension error: Microsoft Visual C++ 14.0 is required. Get it with "Microsoft Visual C++ Build Tools": http://landinghub.visualstudio.com/vis

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

    使用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/

  • C++使用ffmpeg实现rtsp取流的代码

    目录 C++ 使用ffmpeg实现rtsp取流 环境 下载 安装编译依赖 配置 ffmepg采用rtsp取流流程图 CMakeLists.txt编写方法 实现代码 C++ 使用ffmpeg实现rtsp取流 flyfish 环境 Ubuntu 18.04Qt 5.14.2FFmpeg-n5.0.1 下载 https://git.ffmpeg.org/ffmpeg.githttps://github.com/FFmpeg/FFmpeg 这里选择n5.0.1版本 安装编译依赖 sudo apt-get

  • 解决docker pull镜像报错的问题

    描述: 在win10下安装VM,在VM里运行docker,使用docker pull拉取镜像时报错 一. Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers) 原因: 使用docker pull 命令拉取镜像时,如果不添加额外的信息如docker pull nginx

  • 快速解决百度编译器json报错的问题

    在MyEclipse中JSON字符串的换行值是不同的,必须以'/n'换行,如果只是json验证的问题,可以把json的验证关掉试试. 点击所在的项目->Project->Proterties->MyEclipse->Validation,把JSON Validator中的Manual和Build的对号给去掉,然后apply,确定,clean缓存. 清除myeclipse缓存的方法如下 找到软件导航窗内的project下的clean,选择要清除缓存的项目,点击clean projec

  • 解决laravel 5.1报错:No supported encrypter found的办法

    本文主要介绍了关于解决laravel 5.1报错:No supported encrypter found的办法,分享出来供大家参考学习,下面来看看详细的介绍: 问题描述 在使用laravel5.1进行项目开发的时候,出现了"No supported encrypter found. The cipher and / or key length are invalid."的报错信息,导致页面无法显示. 网上的绝大多数答案都是直接执行PHP artisan key:generate即可.

  • 解决Layui中layer报错的问题

    问题描述: Uncaught ReferenceError: layer is not defined 解决方法,查看网上说名,是非独立版导致直接使用layer导致,只需要在使用时加一说明,申明一下使用. layui.use(['element','layer'], function(){ var element = layui.element,layer=layui.layer; //一些事件监听 element.on('nav(topBarNav)', function(data){ con

  • vue 解决循环引用组件报错的问题

    做项目时遇到使用循环组件,因为模式一样,只有数据不一样.但是按照普通的组件调用格式来做时报错,错误信息为Unknown custom element: <pop> - did you register the component correctly? For recursive components, make sure to provide the "name" option. 查询了官方文档,还有其他的资料,发现是循环调用组件时,组件比vue实例后创建,官方文档里写组件

  • 解决pip install xxx报错SyntaxError: invalid syntax的问题

    python--pip install xxx报错SyntaxError: invalid syntax 在安装好python后,进入python运行环境后,因为我要用pip安装开发Web App需要的第三方库,执行pip install aiohttp,发现会报错SyntaxError: invalid syntax,刚开始以为是拼写或者空格问题或者python版本问题,结果用pip3还是一样的. 然后百度了一下,发现原来用pip安装时都要在cmd命令行里启动的,而在python中无法运行.退

  • vue如何解决循环引用组件报错的问题

    问题由来 最近在做项目的时候遇到使用循环组件,因为模式一样,只有数据不一样.按照普通组件调用格式来做的时候总是报错,错误信息为[Vue warn]: Unknown custom element: <selfile> - did you register the component correctly? For recursive components, make sure to provide the "name" option. 解决方案 查询了网上各种资料之后,发现是

  • Python 解决OPEN读文件报错 ,路径以及r的问题

    Python 中 'unicodeescape' codec can't decode bytes in position XXX: trun错误解决方案 背景描述 今天在运用Python pillow模块处理图片时遇到一个错误 SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape 刚开始以为是图片名字有中文,不识别,于是

随机推荐