如何基于C++解決RTSP取流報錯問題
更新時間:2020年08月14日 10:49:38 作者:wangaolin
這篇文章主要介紹了如何基于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`
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- 15種?C++?常見報錯原因分析
- c++報錯問題解決方案lvalue required as left operand of assignment
- C++?OpenCV裁剪圖片時發(fā)生報錯的解決方式
- 解決pip?install?dlib報錯C++11?is?required?to?use?dlib
- Python3安裝模塊報錯Microsoft Visual C++ 14.0 is required的解決方法
- 解決安裝mysqlclient的時候出現(xiàn)Microsoft Visual C++ 14.0 is required報錯
- C或C++報錯:ld returned 1 exit status報錯的原因及解決方法
相關(guān)文章
C++ 中靜態(tài)成員函數(shù)與非靜態(tài)成員函數(shù)的區(qū)別
這篇文章主要介紹了C++ 中靜態(tài)成員函數(shù)與非靜態(tài)成員函數(shù)的區(qū)別的相關(guān)資料,需要的朋友可以參考下2017-05-05C++實現(xiàn)LeetCode(768.可排序的最大塊數(shù)之二)
這篇文章主要介紹了C++實現(xiàn)LeetCode(768.可排序的最大塊數(shù)之二),本篇文章通過簡要的案例,講解了該項技術(shù)的了解與使用,以下就是詳細內(nèi)容,需要的朋友可以參考下2021-07-07c++ builder TreeView控件節(jié)點遍歷代碼
這篇文章介紹了c++ builder TreeView控件節(jié)點遍歷代碼,有需要的朋友可以參考一下2013-09-09