denseflow是一个常用的提取光流和图片的库。花了一下午时间非常费劲的安装denseflow,总算是搞定了。下面介绍整个过程:
首先按照:
https://github.com/innerlee/setup
安装好依赖的库:boost和opencv。boost的安装应该没有什么问题,但是opencv的安装会比较麻烦。因为denseflow对opencv有各种各样的要求,比方说需要支持cuda,所以就简单的安装opencv是不行的,要按照zzopencv.sh里进行安装。注意,安装opencv时需要提前安装好各种依赖库,具体步骤可以参考:
https://github.com/open-mmlab/denseflow/blob/master/INSTALL.md
我在安装opencv的时候,始终报错,报错信息如:
/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
最终我的解决方案是使用:
sudo bash zzopencv.sh
就是加了一个sudo来解决的。这一步安装opencv很重要。如果只是安装好一个opencv,没有按照要求来,比如让opencv支持cuda,那么后面按照denseflow也会失败。报错信息如:
[100%] Linking CXX executable denseflow
libzzdenseflow.a(denseflow_gpu.cpp.o):在函数‘DenseFlow::calc_optflows_imp(FlowBuffer const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int, bool, cv::cuda::Stream&)’中:
denseflow_gpu.cpp:(.text+0x296b):对‘cv::cuda::OpticalFlowDual_TVL1::create(double, double, double, int, int, double, int, double, double, bool)’未定义的引用
denseflow_gpu.cpp:(.text+0x2a08):对‘cv::cuda::FarnebackOpticalFlow::create(int, double, bool, int, int, int, double, int)’未定义的引用
denseflow_gpu.cpp:(.text+0x2a9f):对‘cv::cuda::BroxOpticalFlow::create(double, double, double, int, int, int)’未定义的引用
/home/uk/anaconda3/lib/libharfbuzz.so.0:对‘FT_Done_MM_Var’未定义的引用
//lib/x86_64-linux-gnu/libblkid.so.1:对‘uuid_unparse@UUID_1.0’未定义的引用
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
这就是因为opencv不支持cuda引起的。按照这样的方式配置好之后,安装denseflow还是会失败,还有2件事需要做。
第一,参考如下的issue:
https://github.com/open-mmlab/mmaction/issues/9
补充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/
注意,这里的代码可能需要改,根绝自己下载的SDK的版本以及cuda的版本需要调整。
第二,修改zzdenseflow.sh文件,指定opencv的位置以及cuda的位置。
原本的cmake命令为:
cmake -DCMAKE_INSTALL_PREFIX="$ROOTDIR" ..
指定opencv和cuda后命令为:
sudo cmake -DCMAKE_INSTALL_PREFIX="$ROOTDIR" -D OpenCV_DIR=/root/app/src/opencv/build/ -D CUDA_TOOLKIT_ROOT_DIR=/usr/local/cuda ..
这里的命令也需要根据自己的实际安装路径去修改。如果不指定cuda路径,会出现错误:
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
如果不指定opencv路径,会出现错误:
[100%] Linking CXX executable denseflow
libzzdenseflow.a(denseflow_gpu.cpp.o):在函数‘DenseFlow::calc_optflows_imp(FlowBuffer const&, std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&, int, bool, cv::cuda::Stream&)’中:
denseflow_gpu.cpp:(.text+0x296b):对‘cv::cuda::OpticalFlowDual_TVL1::create(double, double, double, int, int, double, int, double, double, bool)’未定义的引用
denseflow_gpu.cpp:(.text+0x2a08):对‘cv::cuda::FarnebackOpticalFlow::create(int, double, bool, int, int, int, double, int)’未定义的引用
denseflow_gpu.cpp:(.text+0x2a9f):对‘cv::cuda::BroxOpticalFlow::create(double, double, double, int, int, int)’未定义的引用
/home/uk/anaconda3/lib/libharfbuzz.so.0:对‘FT_Done_MM_Var’未定义的引用
//lib/x86_64-linux-gnu/libblkid.so.1:对‘uuid_unparse@UUID_1.0’未定义的引用
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
此外,如果出现错误信息如:
/home/m/src/denseflow/src/denseflow_gpu.cpp:2:10: fatal error: opencv2/cudaarithm.hpp: No such file or directory
#include “opencv2/cudaarithm.hpp”
可以参考解决方案:
https://blog.csdn.net/qq_26663997/article/details/118305779
最终:
sudo bash zzdenseflow.sh
安装成功!
[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
|