终于安装配置完成 OpenCV,兴冲冲写了个 rtsp 网络摄像头测试程序,结果连不上:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
int main(int, char**) {
cv::VideoCapture vcap;
cv::Mat image;
const std::string videoStreamAddress = "rtsp://admin:password@192.168.xxx.xxx:xxx/cam/realmonitor?channel=1&subtype=0&unicast=true";
if(!vcap.open(videoStreamAddress)) {
std::cout << "Error opening video stream or file" << std::endl;
return -1;
}
cv::namedWindow("Output Window");
for(;;) {
if(!vcap.read(image)) {
std::cout << "No frame" << std::endl;
cv::waitKey();
}
cv::imshow("Output Window", image);
if(cv::waitKey(1) >= 0) break;
}
}
查了以下资料,说是ubuntu没安装 ffmpeg,按照下面方法安装完成后,就 OK 了。
$ sudo add-apt-repository ppa:kirillshkrogalev/ffmpeg-next
$ sudo apt-get update
$ sudo apt-get install ffmpeg
终于可以在 ubuntu 系统下开始机器视觉程序设计了!