#include <opencv2\core.hpp>
#include <opencv2\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
string s_rtsp = "rtsp://admin:zhanshhaikang123@10.1.139.170:554/Streaming/Channels/101";//修改了端口554,预览取流//RTSP端口默认554未做改动
VideoCapture camer_cap;
bool flag = camer_cap.open(s_rtsp.c_str());
if (!camer_cap.isOpened()) {
cout << "rstp打开失败,\r\n1.请确认编译opencv的时候,添加了ffmpeg选项。\r\n2.使用vlc播放器确认rtsp连接字符串正确" << endl;
}else
{
Mat frame;
namedWindow("video");
while (camer_cap.read(frame))
{
imshow("video", frame);//frame图像尺寸是1080x1920
waitKey(1);
}
camer_cap.release();
}
return 0;
}
----------------------------------------------------------------
1.使用自己编译的Opencv4.5.2运行以上程序,bool flag = camer_cap.open(s_rtsp.c_str());一直返回false
2.改用官网下载的opencv4.4.0运行以上程序,正常读取视频帧
结论:可能是自己编译opencv4.5.2的时候没有包含ffmpeg