Painful installation of opencv and denseflow

Posted by jax_15 on Sat, 20 Nov 2021 03:29:56 +0100

Denseflow is a common library for extracting optical flow and pictures. It took a whole afternoon to install denseflow, and it was finally done. The whole process is described below:

First, according to:

https://github.com/innerlee/setup

Install the dependent libraries: boost and OpenCV. There should be no problem with the installation of boost, but the installation of OpenCV will be troublesome. Because denseflow has various requirements for opencv, such as cuda support, it is not feasible to simply install OpenCV. Install it according to zzopencv.sh. Note that various dependent libraries need to be installed in advance when installing OpenCV. For specific steps, please refer to:

https://github.com/open-mmlab/denseflow/blob/master/INSTALL.md

When I install opencv, I always report an error. The error information is as follows:

/anaconda/envs/py38_default/x86_64-conda-linux-gnu/include/c++/7.5.0/type_traits(2985): error: "constexpr" is not valid here

/anaconda/envs/py38_default/x86_64-conda-linux-gnu/include/c++/7.5.0/type_traits(2988): error: "is_assignable_v" is not a function or static data member

/anaconda/envs/py38_default/x86_64-conda-linux-gnu/include/c++/7.5.0/type_traits(2988): error: "constexpr" is not valid here

Error limit reached.
100 errors detected in the compilation of "/tmp/tmpxft_0000c0d5_00000000-6_gpu_mat.cpp1.ii".
Compilation terminated.
CMake Error at cuda_compile_1_generated_gpu_mat.cu.o.RELEASE.cmake:281 (message):
  Error generating file
  /home/v-jieshao/app/src/opencv/build/modules/core/CMakeFiles/cuda_compile_1.dir/src/cuda/./cuda_compile_1_generated_gpu_mat.cu.o

My final solution is to use:

sudo bash zzopencv.sh

A sudo was added to solve the problem. This step is very important to install OpenCV. If you just install an opencv and don't follow the requirements, such as making opencv support cuda, you will also fail to follow denseflow later. Error information, such as:

[100%] Linking CXX executable denseflow
libzzdenseflow.a(denseflow_gpu.cpp.o): In function'DenseFlow::calc_optflows_imp(FlowBuffer const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int, bool, cv::cuda::Stream&)'Medium:
denseflow_gpu.cpp:(.text+0x296b): yes'cv::cuda::OpticalFlowDual_TVL1::create(double, double, double, int, int, double, int, double, double, bool)'Undefined reference
denseflow_gpu.cpp:(.text+0x2a08): yes'cv::cuda::FarnebackOpticalFlow::create(int, double, bool, int, int, int, double, int)'Undefined reference
denseflow_gpu.cpp:(.text+0x2a9f): yes'cv::cuda::BroxOpticalFlow::create(double, double, double, int, int, int)'Undefined reference
/home/uk/anaconda3/lib/libharfbuzz.so.0: yes'FT_Done_MM_Var'Undefined reference
//lib/x86_ 64 Linux GNU / libblkid. So. 1: for 'UUID'_ unparse@UUID_ 1.0 'undefined reference
collect2: error: ld returned 1 exit status
CMakeFiles/denseflow.dir/build.make:174: recipe for target 'denseflow' failed
make[2]: *** [denseflow] Error 1
CMakeFiles/Makefile2:123: recipe for target 'CMakeFiles/denseflow.dir/all' failed
make[1]: *** [CMakeFiles/denseflow.dir/all] Error 2
Makefile:148: recipe for target 'all' failed
make: *** [all] Error 2

This is because opencv does not support cuda. After configuring in this way, the installation of denseflow will still fail. There are two things to do.

First, refer to the following issue:

https://github.com/open-mmlab/mmaction/issues/9

Supplement some missing codes in cuda:

(For CUDA 10.0 only) CUDA 9.x should have no problem.
Video decoder is deprecated in CUDA 10.0. To handle this, download NVIDIA VIDEO CODEC SDK and copy the header files to your cuda path (/usr/local/cuda-10.0/include/ for example). Note that you may have to do as root.

unzip Video_Codec_SDK_9.0.20.zip
cp Video_Codec_SDK_9.0.20/include/nvcuvid.h /usr/local/cuda-10.0/include/
cp Video_Codec_SDK_9.0.20/include/cuviddec.h /usr/local/cuda-10.0/include/

Note that the code here may need to be changed. The SDK version you downloaded and cuda version need to be adjusted.

Second, modify the zzdenseflow.sh file to specify the location of opencv and cuda.

The original cmake command is:

cmake -DCMAKE_INSTALL_PREFIX="$ROOTDIR" ..

After specifying opencv and cuda, the command is:

sudo cmake -DCMAKE_INSTALL_PREFIX="$ROOTDIR"  -D OpenCV_DIR=/root/app/src/opencv/build/  -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda ..

The commands here also need to be modified according to their actual installation path. If you do not specify a cuda path, an error occurs:

CMake Error at /root/app/src/opencv/build/OpenCVConfig.cmake:111 (message):
  OpenCV static library was compiled with CUDA 10.2 support.  Please, use the
  same version or rebuild OpenCV with CUDA 11.1

If the opencv path is not specified, an error occurs:

[100%] Linking CXX executable denseflow
libzzdenseflow.a(denseflow_gpu.cpp.o): In function'DenseFlow::calc_optflows_imp(FlowBuffer const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int, bool, cv::cuda::Stream&)'Medium:
denseflow_gpu.cpp:(.text+0x296b): yes'cv::cuda::OpticalFlowDual_TVL1::create(double, double, double, int, int, double, int, double, double, bool)'Undefined reference
denseflow_gpu.cpp:(.text+0x2a08): yes'cv::cuda::FarnebackOpticalFlow::create(int, double, bool, int, int, int, double, int)'Undefined reference
denseflow_gpu.cpp:(.text+0x2a9f): yes'cv::cuda::BroxOpticalFlow::create(double, double, double, int, int, int)'Undefined reference
/home/uk/anaconda3/lib/libharfbuzz.so.0: yes'FT_Done_MM_Var'Undefined reference
//lib/x86_ 64 Linux GNU / libblkid. So. 1: for 'UUID'_ unparse@UUID_ 1.0 'undefined reference
collect2: error: ld returned 1 exit status
CMakeFiles/denseflow.dir/build.make:174: recipe for target 'denseflow' failed
make[2]: *** [denseflow] Error 1
CMakeFiles/Makefile2:123: recipe for target 'CMakeFiles/denseflow.dir/all' failed
make[1]: *** [CMakeFiles/denseflow.dir/all] Error 2
Makefile:148: recipe for target 'all' failed
make: *** [all] Error 2

In addition, if an error message appears, such as:

/home/m/src/denseflow/src/denseflow_gpu.cpp:2:10: fatal error: opencv2/cudaarithm.hpp: No such file or directory
#include "opencv2/cudaarithm.hpp"

You can refer to the solution:

https://blog.csdn.net/qq_26663997/article/details/118305779

final:

sudo bash zzdenseflow.sh

Installation succeeded!

[100%] Built target denseflow
Install the project...
-- Install configuration: ""
-- Installing: /root/app/bin/denseflow
-- Set runtime path of "/root/app/bin/denseflow" to ""
-- Installing: /root/app/lib/libzzdenseflow.a
denseflow installed on /root/app

Topics: Python OpenCV Algorithm CV