Optical Flow with OpenCV: Difference between revisions
(Created page with "= Optical Flow = == Resources == * https://learnopencv.com/optical-flow-in-opencv/ * https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html * https://github.com/s...") |
|||
(9 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
= Optical Flow = | = Optical Flow = | ||
Optical flow calculations on OpenSuse 15.2 | |||
== Resources == | == Resources == | ||
Line 8: | Line 10: | ||
== Install == | == Install == | ||
=== Python 3 === | |||
To test python examples from the git repo directory learnopencv/Optical-Flow-in-OpenCV in a conda environment is easy | To test python examples from the git repo directory learnopencv/Optical-Flow-in-OpenCV in a conda environment is easy | ||
Line 13: | Line 17: | ||
git clone https://github.com/spmallick/learnopencv.git | git clone https://github.com/spmallick/learnopencv.git | ||
cd learnopencv/Optical-Flow-in-OpenCV/ | cd learnopencv/Optical-Flow-in-OpenCV/ | ||
conda create -n optical-flow | conda create -n optical-flow python=3.8 | ||
conda activate optical-flow | conda activate optical-flow | ||
pip install -r reqirements.txt | pip install -r reqirements.txt | ||
=== C++ === | |||
To run the c++ examples is a bit more involved. The Opensuse packages of opencv do not include all prerequisites and you get an error: | To run the c++ examples is a bit more involved. The Opensuse packages of opencv do not include all prerequisites and you get an error: | ||
Line 21: | Line 27: | ||
fatal error: opencv2/optflow.hpp: No such file or directory | fatal error: opencv2/optflow.hpp: No such file or directory | ||
To get rid of this, use a self compiled version of opencv with contrib part | To get rid of this, use a self compiled version of opencv with contrib part. | ||
It needs up to 2GB RAM per (c)make core, so I limited it to 4 cores. | |||
It chokes if it finds a python2, so I need to disable it | |||
Install prerequisites (some are optional...) | |||
sudo zypper in gtk3-devel ffmpeg-3-libavcodec-devel ffmpeg-3-libavformat-devel ffmpeg-3-libavutil-devel ffmpeg-3-libswscale-devel ffmpeg-3-libavresample-devel libva-devel tesseract-ocr-devel vtk-devel | |||
Build and Install OpenCV | |||
wget -O opencv.zip https://github.com/opencv/opencv/archive/master.zip | wget -O opencv.zip https://github.com/opencv/opencv/archive/master.zip | ||
Line 28: | Line 42: | ||
unzip opencv_contrib.zip | unzip opencv_contrib.zip | ||
mkdir -p build && cd build | mkdir -p build && cd build | ||
cmake -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-master/modules ../opencv-master | cmake -DBUILD_opencv_python2=OFF -DPYTHON3_EXECUTABLE=/home/joachim/miniconda3/envs/Optical-Flow-in-OpenCV/bin/python -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-master/modules ../opencv-master | ||
cmake --build . --parallel 4 | |||
make install | |||
Now compile the sample code | |||
cd algorithms | |||
cmake . | |||
make -j4 | |||
== Execute Examples == | == Execute Examples == | ||
Just paste the example commands from the git repo readme, (any mp4 worked) e.g.: | |||
python3 demo.py --algorithm lucaskanade --video_path videos/car.mp4 | |||
This will show 2 windows, one with an example video and one with the flow information | |||
For the c++ installation, this would be the equivalent command: | |||
./OpticalFlow ../videos/car.mp4 lucaskanade |
Latest revision as of 07:48, 11 May 2021
Optical Flow
Optical flow calculations on OpenSuse 15.2
Resources
- https://learnopencv.com/optical-flow-in-opencv/
- https://docs.opencv.org/master/d7/d9f/tutorial_linux_install.html
- https://github.com/spmallick/learnopencv.git
Install
Python 3
To test python examples from the git repo directory learnopencv/Optical-Flow-in-OpenCV in a conda environment is easy
git clone https://github.com/spmallick/learnopencv.git cd learnopencv/Optical-Flow-in-OpenCV/ conda create -n optical-flow python=3.8 conda activate optical-flow pip install -r reqirements.txt
C++
To run the c++ examples is a bit more involved. The Opensuse packages of opencv do not include all prerequisites and you get an error:
fatal error: opencv2/optflow.hpp: No such file or directory
To get rid of this, use a self compiled version of opencv with contrib part. It needs up to 2GB RAM per (c)make core, so I limited it to 4 cores. It chokes if it finds a python2, so I need to disable it
Install prerequisites (some are optional...)
sudo zypper in gtk3-devel ffmpeg-3-libavcodec-devel ffmpeg-3-libavformat-devel ffmpeg-3-libavutil-devel ffmpeg-3-libswscale-devel ffmpeg-3-libavresample-devel libva-devel tesseract-ocr-devel vtk-devel
Build and Install OpenCV
wget -O opencv.zip https://github.com/opencv/opencv/archive/master.zip wget -O opencv_contrib.zip https://github.com/opencv/opencv_contrib/archive/master.zip unzip opencv.zip unzip opencv_contrib.zip mkdir -p build && cd build cmake -DBUILD_opencv_python2=OFF -DPYTHON3_EXECUTABLE=/home/joachim/miniconda3/envs/Optical-Flow-in-OpenCV/bin/python -DOPENCV_EXTRA_MODULES_PATH=../opencv_contrib-master/modules ../opencv-master cmake --build . --parallel 4 make install
Now compile the sample code
cd algorithms cmake . make -j4
Execute Examples
Just paste the example commands from the git repo readme, (any mp4 worked) e.g.:
python3 demo.py --algorithm lucaskanade --video_path videos/car.mp4
This will show 2 windows, one with an example video and one with the flow information
For the c++ installation, this would be the equivalent command:
./OpticalFlow ../videos/car.mp4 lucaskanade