VS2015配置OpenCV-contribu4.1.1及缺少xfeatures2d等无法打开包括文件: “features2d/test/test_detectors_regression.im问题

一、配置环境:VS2015+OpenCV4.1.1+OpenCV_contrib-4.1.1+CMake3.17.1

下载链接:

OpenCV:https://opencv.org/releases/

OpenCV_contrib:https://github.com/opencv/opencv_contrib/releases   OpenCV_contrib版本必须要与OpenCV版本一致

CMake:https://cmake.org/download/

 

二、安装步骤

2.1 CMake编译

(1)先安装OpenCV.exe,记住安装路径,尽量不要中文。

(2)安装好之后一般是buildsources这两个文件夹。

(3)在OpenCV安装目录下新建一个文件夹,用来保存编译后的结果。如图所示的webuild文件夹。

(4)--点击Configure,选择VS的版本Visual Studio 15 2015 ;第二个选择X64位系统(根据自己系统来),曾在这翻车;然后点击finish等待编译;

Configuring Done 后如果出现红色区域;勾选BUILD_opencv_world,BUILD_EXAMPLES(大体趋势);

此外找到OPENCV_EXTRA_MODULES_PATH,添加路径D:\Program Files\opencv_contrib-4.1.1\modules

然后据说OpenCV4.0之后的版本必须将OPENCV_ENABLE_NONFREE 勾上,翻车之一。

再次点击Configure没有红色为止并 Configuring Done后点击Generate,出现Generatring Done;

2.2 编译VS2015

打开webuild中的OpenCV.sln,右键点击解决方案,重新生成解决方案,等待生成完成;

生成解决方案,翻车多次,总是有错误,一个个解决。

记住选择Debug  +  X64 (根据系统配置来)

然后在CMakeTargets下找到INSTALL,右键仅用于项目,仅生成INSATLL;完成后webuild文件夹里多了一个install文件夹:

到此编译工作基本完成了。

三、配置OpenCV与VS2015的环境

(1)环境变量,系统变量,在path中添加OpenCV的路径:D:\Program Files\opencv4.1.1\opencv\webuild\install\x64\vc14\bin

(2)新建一个空的Debug  +  X64项目,点击菜单栏的"视图"–>“其他窗口”–>“属性管理器”。


在Microsoft.Cpp.x64.user–>VC++目录–>库目录中加入

包含目录:

D:\Program Files\opencv4.1.1\opencv\webuild\install\include

D:\Program Files\opencv4.1.1\opencv\webuild\install\include\opencv2

 

库目录:

D:\Program Files\opencv4.1.1\opencv\webuild\install\x64\vc14\lib

D:\Program Files\opencv4.1.1\opencv\webuild\install\x64\vc14\bin

 

连接器,输入,附加依赖项

附加依赖项:

opencv_world411d.lib
opencv_aruco411d.lib
opencv_bgsegm411d.lib
opencv_bioinspired411d.lib
opencv_calib3d411d.lib
opencv_ccalib411d.lib
opencv_core411d.lib
opencv_datasets411d.lib
opencv_dnn_objdetect411d.lib
opencv_dnn411d.lib
opencv_dpm411d.lib
opencv_face411d.lib
opencv_features2d411d.lib
opencv_flann411d.lib
opencv_fuzzy411d.lib
opencv_gapi411d.lib
opencv_hfs411d.lib
opencv_highgui411d.lib
opencv_img_hash411d.lib
opencv_imgcodecs411d.lib
opencv_imgproc411d.lib
opencv_line_descriptor411d.lib
opencv_ml411d.lib
opencv_objdetect411d.lib
opencv_optflow411d.lib
opencv_phase_unwrapping411d.lib
opencv_photo411d.lib
opencv_plot411d.lib
opencv_quality411d.lib
opencv_reg411d.lib
opencv_rgbd411d.lib
opencv_saliency411d.lib
opencv_shape411d.lib
opencv_stereo411d.lib
opencv_stitching411d.lib
opencv_structured_light411d.lib
opencv_superres411d.lib
opencv_surface_matching411d.lib
opencv_text411d.lib
opencv_tracking411d.lib
opencv_video411d.lib
opencv_videoio411d.lib
opencv_videostab411d.lib
opencv_xfeatures2d411d.lib
opencv_ximgproc411d.lib
opencv_xobjdetect411d.lib
opencv_xphoto411d.lib

程序读取:

import os
for name in os.listdir('./'):
	print(name)

配置完成!

四、测试结果

 

五、问题

配置完之后无法使用xfeature2d模块,出现无法打开包括文件: “features2d/test/test_detectors_regression.impl.hpp”错误;

无法生成xfeatures2d的动态库:OpenCV源码中opencv/sources/3rdparty/ffmpeg 中缺少opencv_ffmpeg.dllopencv_ffmpeg_64.dll.

1、“boostdesc_bgm.i”: No such file or directory opencv_xfeatures2d D:\OpenCV\opencv_contrib-4.1.1\modules\xfeatures2d\src\boostdesc.cpp 654

在OpenCV-contribu4.1.1路径中D:\Program Files\opencv_contrib-4.1.1\modules\xfeatures2d\src,补齐以下文件,(网上搜索下载放到路径文件夹中)。

2、“features2d/test/test_detectors_regression.impl.hpp”错误、No such file or directory opencv_test_xfeatures2d D:\OpenCV\opencv_contrib-4.1.1\modules\xfeatures2d\test\test_features2d.cpp 51。

 

在OpenCV路径下D:\Program Files\opencv4.1.1\opencv\sources\modules\features2d\test,修改头文件,或者改变文件路径,或者补齐以下5个文件。

test_descriptors_invariance.impl.hpp
test_descriptors_regression.impl.hpp
test_detectors_invariance.impl.hpp
test_detectors_regression.impl.hpp
test_invariance_utils.hpp

将opencv-4.1.1/modules/features2d/test/文件下的5个文件拷贝到opencv_contrib-4.1.1/modules/xfeatures2d/test/文件下。同时修改头文件。

① test_features2d.cpp

#include "features2d/test/test_detectors_regression.impl.hpp"
#include "features2d/test/test_descriptors_regression.impl.hpp"

 

修改成

 

 

#include "test_detectors_regression.impl.hpp"
#include "test_descriptors_regression.impl.hpp"

 

② test_rotation_and_scale_invariance.cpp

 

 

#include "features2d/test/test_detectors_invariance.impl.hpp"
#include "features2d/test/test_descriptors_invariance.impl.hpp"

 

修改成

 

 

#include "test_detectors_invariance.impl.hpp"
#include "test_descriptors_invariance.impl.hpp"

 

修改完了之后再用VS2015重新生成解决方案->INSTALL,发现在D:\OpenCV4.1.1\opencv\webuild\install\x64\vc14\lib的库中终于生成了opencv_xfeatures2d411d.lib。再把它加到附加项中。重复以下 ‘’三‘’中的步骤,会发现生成解决方案时,成功的个数会变多。最后用测试代码进行测试,发现没有问题。

 

 

 

 

 

posted @ 2021-03-17 19:13  code_witness  阅读(1536)  评论(0编辑  收藏  举报