opencv读取网络摄像头的环境配置

我的环境是ubuntu18.04,在执行opencv的cmake之前先装以下依赖包:

apt install pkg-config
apt install ffmpeg
apt install libavformat-dev
apt install libavcodec-dev
apt install libswresample-dev
apt install libswscale-dev
apt install libavutil-dev
apt install libsdl1.2-dev
apt install libgtk2.0-dev

其中libgtx是用到了cv::imshow,需要显示输出。

最后在opencv中:

cmake -D WITH_FFMPEG=ON ..

最后,调用示例如下:

#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:123456@10.10.10.3/Streaming/Channels/1";
	 VideoCapture camer_cap;
	 camer_cap.open(s_rtsp);     //打开视频
	 if (camer_cap.isOpened())   //如果视频不能正常打开则返回
	{
    //获取指定视频类的相关参数信息
    // int width = cap.get(CV_CAP_PROP_FRAME_WIDTH);  //帧宽度
    //int height = cap.get(CV_CAP_PROP_FRAME_HEIGHT); //帧高度
     //int frameRate = cap.get(CV_CAP_PROP_FPS);  //帧率 x frames/s
     //int totalFrames = cap.get(CV_CAP_PROP_FRAME_COUNT); //总帧数
		Mat frame;    //定义Mat变量,用来存储每一帧 
		namedWindow("video");   
		while (camer_cap.read(frame))   ///读取当前帧方法
		{
			imshow("video", frame);//frame图像尺寸是1080x1920   //显示一帧画面 
			waitKey(30);   ; //延时30ms 
		}
	}
	 else
	 {
		 cout << "error when cam open" << endl;
	 }
	 camer_cap.release(); ;//释放资源
	 return 0;
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值