When I use yum, it installs opencv 3.2.0. But I specifically need opencv 2.4.13.
With Anaconda, there is a conda-forge package of opencv but installing that cv2.VideoCapture() api fails.
Also when I am trying to install through tar file of opencv 2.4.13, I am stuck in cmake, getting below errors -
sys/videoio.h not found
libavcodec not found
........
Also cmake is giving bizzare scripting errors. Please help.
Anaconda does not have opencv 2.4.13 compiled with ffmpeg, so if you want to use VideoCapture then opencv needs to be compiled. Descriptive list of steps I followed (strictly for fedora users):
Remove previous opencv
Install Python 2.7
*Please use your python 2.7 package name.
Installation of ffmpeg
Download tarball from their site and extract it. https://www.ffmpeg.org/download.html
*remove option --enable-avfilter-lavf if it gives error.
Installation of OpenCV 2.4.13
Below packages will solve sys/videoio.h error:
Then install these packages:
Download OpenCV of your choice e.g. 2.4.13 from github (select 2.4.13 from Branch -> Tags -> 2.4.13 then chose download from clone):
https://github.com/opencv/opencv
http://opencv.org/releases.html
Extract tar:
Now cmake:
Explanation :
Flags that include 'gpu' text are for turning off gpu compilation, if you want to compile with gpu then set them ON. But gpu will require cuda packages and a graphics card to work.
This flag can also be ignored since we are not compiling with gpu, but it also didn't hurt me keeping it.
-DCUDA_NVCC_FLAGS="-ccbin /home/rishabh/gcc-4.9.4-x86_64/bin/gcc"
If you are facing script errors in cmake then do these-
open file opencv-2.4.13.3/cmake/OpenCVPackaging.cmake
-- add this
-- above this line
Comment out respective lines that are blocking cmake and are useless, in whatever filename is thrown out on console.
e.g. opencv-2.4.13.3/cmake/OpenCVDetectCXXCompiler.cmake
I had problem with line 80-86 so I commented it out because those variables were not doing anything else elsewhere.
After cmake is successful, proceed to make step -
If you are facing any linker errors then you will have to install respective dependencies or set cmake flag to OFF if you do not intend to install those modules.
Post installation steps:
Now add
to following files:
Now run
For Anaconda PATH variable Conflict
remove anaconda path from PATH variable and edit in ~/.bashrc also
export PATH=/usr/lib64/qt-3.3/bin:/usr/lib64/ccache:/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/opt/cuda/bin:/home/rishabh/.local/bin:/home/rishabh/bin:/opt/cuda/bin/
Now logout and login to fedora.
Execute below for Testing:
Output-
True - video read success
False - opencv yet not compiled properly with ffmpeg.