服务器之家

服务器之家 > 正文

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

时间:2021-09-23 13:42     来源/作者:wangaolin

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

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

这是我的代码:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#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`

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

原文链接:https://www.cnblogs.com/wal1317-59/p/13440908.html

标签:

相关文章

热门资讯

yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总
苹果12mini价格表官网报价 iPhone12mini全版本价格汇总 2020-11-13
2021年耽改剧名单 2021要播出的59部耽改剧列表
2021年耽改剧名单 2021要播出的59部耽改剧列表 2021-03-05
返回顶部