小工具知识网

当前位置: 首页 > 行业知识 > Opencv VideoCapture File, Web Camera, RTSP stream

行业知识

Opencv VideoCapture File, Web Camera, RTSP stream

2026-12-03 17:13:34 来源:互联网转载

Video capture

in OpenCV is a really easy task, but for a little bit experienced user.

What is the problem?

The problem is the installation of Opencv without recommended dependencies.

Just install all basic libs that are recommended on the website.

# Basic packagessudo apt-get -y install build-essentialsudo apt-get -y install cmakesudo apt-get -y install pkg-config# Basic dependenciessudo apt-get -y install libgtk2.0-dev python-dev python-numpy# OpenCV dependencies part II.sudo apt-get -y install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libunicap2 libunicap2-dev libdc1394-22-dev libdc1394-22 libdc1394-utils libv4l-0 libv4l-devsudo apt-get -y install libavcodec-dev libavformat-dev libswscale-devsudo apt-get -y install libdc1394-22-dev libdc1394-utilssudo apt-get -y install libjpeg-dev libpng-dev libtiff-dev libjasper-devsudo apt-get -y install libtiff5 libtiff5-devsudo apt-get -y install libopenexr-devsudo apt-get -y install libjasper-dev# Algebrasudo apt-get -y install libeigen3-dev

Install ffmpeg for Opencv.

You need to download and build my own in the case of Debian Jessie or some version of Ubuntu.

Just download, and extract tar archive ffmpeg.tar.bz2.

  • configure instalation ./configure – with Right Params.
  • Make - make -j4
  • install - make install

    You may also like…

    People tracking and head detection in Opencv example.

  • write config ldconfig -v

    Compile opencv

    Check this table during the OpenCV installation. if you have FFMPEG and all AV libs

    AVCODEC AVFORMAT AVUTIL AVSWSCALE you can continue with OpenCV installation.

    Read video file in Opencv

    VideoCapture capture(“input.mp4”);

    Read rtsp stream in Opencv

    VideoCapture capture(“rtsp://USER:PASS@xxx.xxx.xxx.xxx/axis-media/media.amp?camera=2”);

    Some of my next post will be about rtsp stream format. PLS subscribe.

    Read web camera in Opencv

    VideoCapture capture(0);

    Opencv 3 and higher c++ code

    在Linux环境下使用opencv访问rtsp视频的方法,经过opencv+ffmpeg安装后访问网络相机rtsp视频流就是一行代码的事

    #include #include #include #include #include #include "opencv2/video/video.hpp"#include #include #include #include using namespace std;using namespace cv;//Chose input//VideoCapture capture(0);VideoCapture capture("rtsp://USER:PASS@xxx.xxx.xxx.xxx/axis-media/media.amp?camera=2");//VideoCapture capture("input.mp4");// create mat to fill by external sourceMat frame;for(;;){       bool OK = capture.grab();        if (OK == false){        cout           // retrieve a frame of your source           capture.read(frame);          //OR         // capture  frame;       }}
    #include #include using namespace std;using namespace cv;//Chose input//通过以下三行代码分别表示选择视频流来源//VideoCapture capture(0);//这行代码选择usb摄像头的视频源VideoCapture capture("rtsp://USER:PASS@xxx.xxx.xxx.xxx/axis-media/media.amp?camera=2");//这行代码选择访问rtsp视频流!!!!!!//VideoCapture capture("input.mp4");//选择播放本地视频// create mat to fill by external sourceMat frame;for(;;){       bool OK = capture.grab();        if (OK == false){        cout           // retrieve a frame of your source           capture.read(frame);          //OR         // capture  frame;       }}

    参考

    https://www.funvisiontutorials.com/2015/11/opencv-300-videocapture-file-web-camera.html

    https://blog.csdn.net/photonfly/article/details/73373545

上一篇:双机热备服务器怎么实现?

下一篇:织梦后台修改QQ账号教程