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

Valora ·
更新时间:2024-11-10
· 703 次阅读

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

您可能感兴趣的文章:Python3安装模块报错Microsoft Visual C++ 14.0 is required的解决方法解决安装mysqlclient的时候出现Microsoft Visual C++ 14.0 is required报错解决VC++编译报错error C2248的方案解决启动MongoDB错误:error while loading shared libraries: libstdc++.so.6:cannot open shared object file:C++使用MySQL-Connector/C++连接MySQL出现LNK2019错误的解决方法解决Scrapy安装错误:Microsoft Visual C++ 14.0 is required...



rtsp C++ c+

需要 登录 后方可回复, 如果你还没有账号请 注册新账号