zoukankan      html  css  js  c++  java
  • 使用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 ";
            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 ";
                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`

  • 相关阅读:
    浏览器是怎样工作的二:渲染引擎 HTML解析(1)(转)
    凯文.都迪的超级记忆力训练教程
    程序员的修炼之道
    我编程我快乐——程序员的职业规划
    SQL Server 数据库备份和还原认识和总结(一)
    SQL Server 管理数据收集
    汇总SQL Server里的相关运算符、子句、谓词等
    SQL Server 数据库备份和还原认识和总结(二)
    解决报表控件报CS0433错误
    通过笔记本配件,理解抽象类接口和委托事件
  • 原文地址:https://www.cnblogs.com/wal1317-59/p/13440908.html
Copyright © 2011-2022 走看看