在opencv3.2.0+vs2015的环境下,是可以使用opencv读取rtsp流的.
cv::VideoCapture vcap; const std::string videoStreamAddress = "rtsp://admin:test123456@192.168.1.19:55/MPEG-4/ch1/main/av_stream";
rtsp://192.168.1.19/vod/mp4://BigBuckBunny_175k.mov
if (!vcap.open(videoStreamAddress))
{
std::cout << "Error opening video stream or file" << std::endl;
return -1;
}
代码如下:
#include "stdafx.h"
#include
#include
using namespace std;
using namespace cv;
int main()
{
VideoCapture cap;
cap.open("rtsp://192.168.1.19/stream1");
Mat Camera_CImg;
Mat Camera_GImg;
cap.set(CV_CAP_PROP_FRAME_HEIGHT,768);
cap.set(CV_CAP_PROP_FRAME_WIDTH,1024);
if (!cap.isOpened())
return 1024;
while (1)
{
cap>> Camera_CImg;
if(Camera_CImg.empty())
break;
cvtColor(Camera_CImg,Camera_GImg, CV_RGB2GRAY);
imshow("input", Camera_CImg);
if (cvWaitKey(10) == 'q')
break;
}
system("pause");
return 0;
}
作者:老樊Lu码