如何基於C++解決RTSP取流報錯問題
阿新 • • 發佈:2020-08-15
使用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:[email protected]: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`
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支援我們。