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 re***mended dependencies.
Just install all basic libs that are re***mended on the website.
# Basic packages
sudo apt-get -y install build-essential
sudo apt-get -y install cmake
sudo apt-get -y install pkg-config
# Basic dependencies
sudo 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-dev
sudo apt-get -y install libavcodec-dev libavformat-dev libswscale-dev
sudo apt-get -y install libdc1394-22-dev libdc1394-utils
sudo apt-get -y install libjpeg-dev libpng-dev libtiff-dev libjasper-dev
sudo apt-get -y install libtiff5 libtiff5-dev
sudo apt-get -y install libopenexr-dev
sudo apt-get -y install libjasper-dev
# Algebra
sudo 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
***pile 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 <vector>
#include <fstream>
#include <iostream>
#include <math.h>
#include <Windows.h>
#include "opencv2/video/video.hpp"
#include <opencv2/imgproc.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/videoio/videoio.hpp>
#include <opencv2/imgcodecs/imgcodecs.hpp>
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 source
Mat frame;
for(;;)
{
bool OK = capture.grab();
if (OK == false){
cout << "cannot grab" << endl;
}
else{
// retrieve a frame of your source
capture.read(frame);
//OR
// capture >> frame;
}
}
#include <stdio.h>
#include <opencv2/opencv.hpp>
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 source
Mat frame;
for(;;)
{
bool OK = capture.grab();
if (OK == false){
cout << "cannot grab" << endl;
}
else{
// retrieve a frame of your source
capture.read(frame);
//OR
// capture >> frame;
}
}
参考
https://www.funvisiontutorials.***/2015/11/opencv-300-videocapture-file-web-camera.html
https://blog.csdn.***/photonfly/article/details/73373545