如何基于C++解決RTSP取流報(bào)錯(cuò)問題
更新時(shí)間:2020年08月14日 10:49:38 作者:wangaolin
這篇文章主要介紹了如何基于C++解決RTSP取流報(bào)錯(cuò)問題,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
使用g++ opencv_demo.cpp -o test 會(huì)報(bào)以下錯(cuò)誤

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

