当前位置:网站首页>win10+vs2017+denseflow编译
win10+vs2017+denseflow编译
2022-07-02 06:25:00 【wxplol】
由于要训练自己动作识别模型,所以需要制作相关数据集,其中就是要制作光流数据,尝试使用传统opencv来做,发现速度太慢。最后找到denseflow库,于是在此记录在win10下的安装过程。
一、安装依赖
1.1、CUDA
- CUDA (driver version > 400)
这里默认已经安装,搞深度学习安装pyTorch/Tensorflow应该都安装过吧。这里我的cuda环境是:CUDA10.0
C:\Users\Administrator>nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2018 NVIDIA Corporation
Built on Sat_Aug_25_21:08:04_Central_Daylight_Time_2018
Cuda compilation tools, release 10.0, V10.0.130
1.2、OpenCV
- OpenCV (with CUDA support)
这里需要安装支持CUDA的OpenCV,博主在这里卡了好久。。。,这里需要在编译OpenCV时注意以下选项:
BUILD_CUDA_STUBS
:选中OPENCV_DNN_CUDA
:未选中WITH_CUDA
:选中
同时,主要这里需要opencv_contrib
模块,需要和OpenCV一起安装
在选择编译器时,最好选择vs2017
或vs2015
,其他的可能编译不成功。
安装可以参考以下链接:VS2019+opencv4.5+CMake编译opencv_contrib-4.5.0模块(较为详细教程)
1.3、Boost
- Boost
正常安装,网上也有很多相关教程,如:Windows10下配置Boost
二、Cmake编译
2.1、生成可编译文件sln
这里,我们可以参考github上教程直接执行:
git clone https://github.com/open-mmlab/denseflow.git
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=$HOME/app -DUSE_HDF5=no -DUSE_NVFLOW=no ..
也可以在clone
源代码后,使用cmake-gui进行编译,这里我选择第一种方法了。所以,我们需要改相关CMakeLists.txt
文件内容,修改如下:
- 添加OpenCV库
这一步主要是为了让Cmake发现OpenCV的位置,修改如下:
set(OpenCV_DIR D:\\cplusplus\\library\\opencv\\opencv-4.5.2\\build)
具体需要参考你的OpenCV编译的位置。
- 添加Boost库
set(Boost_USE_STATIC_LIBS ON)
set(BOOST_ROOT D:\\cplusplus\\library\\boost_1_73_0)
- 删除pthread依赖
target_link_libraries(${DenseFlow_LIB} ${OpenCV_LIBS} Boost::filesystem ${Boost_LIBRARIES})
完整CMakeLists.txt
文件如下:
cmake_minimum_required(VERSION 3.12)
project(DenseFlow)
option(USE_HDF5 "Whether to build hdf5 for optical flow image saving" OFF)
option(USE_NVFLOW "Whether to use nvidia hardware optical flow" OFF)
set(OpenCV_DIR D:\\cplusplus\\library\\opencv\\opencv-4.5.2\\build)
set(Boost_USE_STATIC_LIBS ON)
set(BOOST_ROOT D:\\cplusplus\\library\\boost_1_73_0)
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -fPIC")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
else()
message(STATUS "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
find_package(CUDA REQUIRED)
find_package(OpenCV REQUIRED)
set(DenseFlow_LIB zzdenseflow)
message(STATUS "OpenCV library status:")
message(STATUS " config: ${OpenCV_DIR}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
find_package(Boost REQUIRED COMPONENTS date_time filesystem iostreams)
message(STATUS "Boost library status:")
message(STATUS " version: ${Boost_VERSION}")
message(STATUS " libraries: ${Boost_LIBRARIES}")
message(STATUS " include path: ${Boost_INCLUDE_DIRS}")
add_library(${DenseFlow_LIB} src/common.cpp src/utils.cpp src/denseflow_gpu.cpp)
include_directories(${OpenCV_INCLUDE_DIRS} ${Boost_INCLUDE_DIRS} include ${PROJECT_BINARY_DIR})
link_directories(${OpenCV_LIB_DIRS})
target_link_libraries(${DenseFlow_LIB} ${OpenCV_LIBS} Boost::filesystem ${Boost_LIBRARIES})
if (USE_HDF5)
find_package(HDF5 COMPONENTS HL REQUIRED)
message(STATUS "HDF5 library status:")
message(STATUS " version: ${HDF5_VERSION}")
message(STATUS " libraries: ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES}")
message(STATUS " include path: ${HDF5_INCLUDE_DIRS} ${HDF5_HL_INCLUDE_DIR}")
set(HDF5_DEFINITION 1)
include_directories(${HDF5_INCLUDE_DIRS} ${HDF5_HL_INCLUDE_DIR})
target_link_libraries(${DenseFlow_LIB} ${HDF5_LIBRARIES} ${HDF5_HL_LIBRARIES})
else()
set(HDF5_DEFINITION 0)
endif()
if (USE_NVFLOW)
set(NVFLOW_DEFINITION 1)
else()
set(NVFLOW_DEFINITION 0)
endif()
configure_file(
"${PROJECT_SOURCE_DIR}/include/config.h.in"
"${PROJECT_BINARY_DIR}/config.h"
)
add_executable(denseflow tools/denseflow.cpp)
target_link_libraries(denseflow ${DenseFlow_LIB})
install (
TARGETS denseflow ${DenseFlow_LIB}
RUNTIME DESTINATION bin
ARCHIVE DESTINATION lib
LIBRARY DESTINATION lib
)
执行完成后可以发现在源代码下有.sln
文件,打开就可以进行vs编译了。
2.2、编译生成denseflow.exe
点击打开vs2017,进行编译。会出现以下错误:
- error C2872: “ACCESS_MASK”: 不明确的符号
原因:include/common.h
中using namespace cv;
造成的空间冲突造成的
解决方法:删除include/common.h
中的using namespace cv;
空间命名,同时,需要在用到OpenCV中函数前面添加cv::
命名空间
如:void convertFlowToImage(const Mat &flow_x, const Mat &flow_y, Mat &img_x, Mat &img_y, double lowerBound,double higherBound);
改为void convertFlowToImage(const cv::Mat &flow_x, const cv::Mat &flow_y, cv::Mat &img_x, cv::Mat &img_y, double lowerBound,double higherBound);
其他地方也与之类似。这需要把所有相关代码都改了,不然会报错。
- fatal error C1083: 无法打开包括文件: “sys/syscall.h”: No such file or directory
原因:这个头文件时linux上的,如果在windwos上的话,需要改为windows.h
头文件
解决方法:在src/denseflow_gpu.cpp
注销#include <sys/syscall.h>
,添加以下内容:
//#include <sys/syscall.h>
#if __linux
#include <sys/syscall.h>
#elif defined(_WIN32) || defined(_WIN64)
#include <windows.h> // Or something like it.
#endif
最终,我们编译成功。
在build/Release
文件夹下发现我们生成的denseflow.exe
。
边栏推荐
- Oracle apex 21.2 installation and one click deployment
- Module not found: Error: Can't resolve './$$_gendir/app/app.module.ngfactory'
- One field in thinkphp5 corresponds to multiple fuzzy queries
- 一份Slide两张表格带你快速了解目标检测
- Spark SQL task performance optimization (basic)
- SSM二手交易网站
- Drawing mechanism of view (3)
- @Transitional step pit
- Pyspark build temporary report error
- 解决万恶的open failed: ENOENT (No such file or directory)/(Operation not permitted)
猜你喜欢
[introduction to information retrieval] Chapter 6 term weight and vector space model
JSP智能小区物业管理系统
MySQL has no collation factor of order by
软件开发模式之敏捷开发(scrum)
Agile development of software development pattern (scrum)
Implementation of purchase, sales and inventory system with ssm+mysql
Principle analysis of spark
一份Slide两张表格带你快速了解目标检测
ssm人事管理系统
SSM personnel management system
随机推荐
Illustration of etcd access in kubernetes
Tencent machine test questions
ERNIE1.0 与 ERNIE2.0 论文解读
Principle analysis of spark
ORACLE EBS 和 APEX 集成登录及原理分析
Practice and thinking of offline data warehouse and Bi development
机器学习理论学习:感知机
Oracle apex 21.2 installation and one click deployment
Oracle 11g sysaux table space full processing and the difference between move and shrink
ORACLE EBS DATAGUARD 搭建
SSM personnel management system
Proteus -- RS-232 dual computer communication
Three principles of architecture design
JSP intelligent community property management system
One field in thinkphp5 corresponds to multiple fuzzy queries
Oracle EBS DataGuard setup
腾讯机试题
深度学习分类优化实战
PHP uses the method of collecting to insert a value into the specified position in the array
Find in laravel8_ in_ Usage of set and upsert