Opencv VideoCapture File, Web Camera, RTSP stream

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 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

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 <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.com/2015/11/opencv-300-videocapture-file-web-camera.html

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

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-02-01 10:04:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-02-01 10:04:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-02-01 10:04:03       87 阅读
  4. Python语言-面向对象

    2024-02-01 10:04:03       96 阅读

热门阅读

  1. pat乙类1002

    2024-02-01 10:04:03       50 阅读
  2. 一起学习飞桨 深度强化学习算法DQN

    2024-02-01 10:04:03       50 阅读
  3. C++结合OpenCV实现视频播放器

    2024-02-01 10:04:03       45 阅读
  4. python查询xml类别

    2024-02-01 10:04:03       48 阅读
  5. C++ 万能函数接口

    2024-02-01 10:04:03       48 阅读
  6. 1697. 检查边长度限制的路径是否存在

    2024-02-01 10:04:03       59 阅读
  7. 算法总结归纳(第十二天)(剩余的图论)

    2024-02-01 10:04:03       59 阅读
  8. centos7 arm服务器配置深度学习环境之cuda安装

    2024-02-01 10:04:03       66 阅读
  9. 制作ubuntu-base-23.10-base-armhf的根文件系统rootfs

    2024-02-01 10:04:03       59 阅读
  10. OpenGL查询对象 Query Objects

    2024-02-01 10:04:03       38 阅读
  11. C# 泛型类型详解:编写更安全、可重用的代码

    2024-02-01 10:04:03       47 阅读