我正在尝试编译OpenCV,以便它具有sift模块。
我使用this tutorial下载了CMake。
我还下载并解压缩了opencv-4.3.0和opencv_contrib。
我制作了一个空文件夹,打开终端,并使用以下行导航至该文件夹:
cd ~/opencvMaster/build
然后,当我在终端的这个空白文件夹中时,我运行了以下行:
cmake -DOPENCV_ENABLE_NONFREE:BOOL=ON -DOPENCV_EXTRA_MODULES_PATH= ~/openCVMaster/opencv_contrib-master/modules ~/openCVMaster/opencv-4.3.0
它配置并生成了文件。然后输入make
。出现以下错误:
[ 82%] Building CXX object modules/xfeatures2d/CMakeFiles/opencv_xfeatures2d.dir/src/boostdesc.cpp.o
~/opencvMaster/opencv_contrib-e6f32c6a69043456a806a4e802ee3ce7b7059c93/modules/xfeatures2d/src/boostdesc.cpp:654:20: fatal error: boostdesc_bgm.i: No such file or directory
#include "boostdesc_bgm.i"
^~~~~~~~~~~~~~~~~
compilation terminated.
我遵循了发现的建议here,并添加了以下文件:
cd ~/openCVMaster/opencv_contrib-4.3.0/modules/xfeatures2d/src
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_lbgm.i >boostdesc_lbgm.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_256.i >boostdesc_binboost_256.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_128.i >boostdesc_binboost_128.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_binboost_064.i >boostdesc_binboost_064.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_hd.i >boostdesc_bgm_hd.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm_bi.i >boostdesc_bgm_bi.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/34e4206aef44d50e6bbcd0ab06354b52e7466d26/boostdesc_bgm.i >boostdesc_bgm.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_120.i > vgg_generated_120.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_64.i >vgg_generated_64.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_48.i >vgg_generated_48.i
curl wget https://raw.githubusercontent.com/opencv/opencv_3rdparty/fccf7cd6a4b12079f73bbfb21745f9babcd4eb1d/vgg_generated_80.i >vgg_generated_80.i
这是向前迈出的一步:不再有与vgg或boostdesc有关的错误。出现了一个新错误:opencv_contrib-master/modules/xfeatures2d/test/test_features2d.cpp:51:10: fatal error: features2d/test/test_detectors_regression.impl.hpp: No such file or directory
按照ah-ma here的建议,我下载了https://github.com/opencv/opencv/tree/master/modules
。下载后,我找到了其子文件夹'features2d'并将其放在opencv_contrib-master/modules/xfeatures2d/test/
中。
仍然出现错误-
~/openCVMaster/opencv_contrib-master/modules/xfeatures2d/test/features2d/misc/java/src/cpp/features2d_converters.cpp:2:10: fatal error: common.h: No such file or directory
#include "common.h"
我添加了以下内容:
cd ~/openCVMaster/opencv_contrib-master/modules/xfeatures2d/test/features2d/misc/java/src/cpp
curl wget https://raw.githubusercontent.com/ray-project/common/master/common.h > common.h
我再次运行make
,并遇到以下错误:
~/openCVMaster/opencv_contrib-master/modules/xfeatures2d/test/features2d/misc/java/src/cpp/features2d_converters.cpp: In function ‘void Mat_to_vector_KeyPoint(cv::Mat&, std::vector<cv::KeyPoint>&)’:
~/openCVMaster/opencv_contrib-master/modules/xfeatures2d/test/features2d/misc/java/src/cpp/features2d_converters.cpp:7:38: error: ‘LOGD’ was not declared in this scope
#define CHECK_MAT(cond) if(!(cond)){ LOGD("FAILED: " #cond); return; }
~/openCVMaster/opencv_contrib-master/modules/xfeatures2d/test/features2d/misc/java/src/cpp/features2d_converters.cpp:14:5: note: in expansion of macro ‘CHECK_MAT’
CHECK_MAT(mat.type()==CV_32FC(7) && mat.cols==1);
^~~~~~~~~
~/openCVMaster/opencv_contrib-master/modules/xfeatures2d/test/features2d/misc/java/src/cpp/features2d_converters.cpp: In function ‘void Mat_to_vector_DMatch(cv::Mat&, std::vector<cv::DMatch>&)’:
~/openCVMaster/opencv_contrib-master/modules/xfeatures2d/test/features2d/misc/java/src/cpp/features2d_converters.cpp:7:38: error: ‘LOGD’ was not declared in this scope
#define CHECK_MAT(cond) if(!(cond)){ LOGD("FAILED: " #cond); return; }
欢迎任何建议。
答案 0 :(得分:1)
# Step 1: Install VS 2017 for cmake
# Step 2: Install CMake
从https://cmake.org/download/下载并安装CMake v3.10.0。
在安装过程中,选择“将CMake添加到系统路径”
# step 3: install Anaconda
# step 4: Download and extract opencv-3.3.1 and opencv_contrib-3.3.1
Go to https://github.com/opencv/opencv/releases and download opencv-3.3.1 source code zip
转到https://github.com/opencv/opencv_contrib/releases并下载opencv_contrib-3.3.1源代码zip
提取两个zip文件。尽管您可以在任何位置保留opencv和opencv_contrib文件夹,但我建议您将两者都保留在同一目录中。我已经将这两个文件夹放在“我的文档”目录中。
注意:从这里开始,我们将opencv-3.3.1文件夹的路径称为OPENCV_PATH。例如,在我的情况下,OPENCV_PATH是C:/ Users / Vaibhaw Chandel / Documents / opencv-3.3.1
根据您保存opencv-3.3.1文件夹的位置,此路径将有所不同。
运行Cmake,在“源代码在哪里”框中,写入OPENCV_PATH的值(这是opencv-3.3.1文件夹的路径)和构建目录的路径。我们将选择构建目录为OPENCV_PATH / build
当系统提示您选择编译器时,选择Visual Studio 14 2015 Win64。
单击完成。现在,CMake将在系统目录中查找并生成makefile。
我们将几乎不更改CMake生成的默认配置。单击图像以查看大图。
选中“ INSTALL_C_EXAMPLES”和“ INSTALL_PYTHON_EXAMPLES” 在标志“ OPENCV_EXTRA_MODULES_PATH”中,给出opencv_contrib-3.3.1中模块目录的路径。在我们的案例中,我们将opencv_contrib-3.3.1保留在Documents文件夹中,因此路径为“ C:/ Users / Vaibhaw Chandel / Documents / opencv_contrib-3.3.1 / modules” 现在,单击“配置”以应用这些更改。
在Windows 10上,opencv_saliency模块无法构建。因此,我们将其禁用。取消选中BUILD_opencv_saliency 现在,再次单击配置以包含此更改。
本节仅适用于希望同时为Python2和Python 3生成OpenCV二进制文件的人。如果仅使用2个或3个Python,则应跳过本节。
CMake无法找到我的Python3文件的路径。
所以我手动添加了Python3的路径 现在,再次单击配置。配置完成后,在搜索栏中搜索opencv_python,将自动检查BUILD_opencv_python2和BUILD_opencv_python3。现在我们确定在编译后将生成适用于Python2和Python 3的OpenCV二进制文件。
如果CMake能够正确配置,则应说“配置完成”。 点击生成。
注意:每当您对CMake生成的配置进行任何更改(选中/取消选中复选框或更改路径)时,请始终单击“配置并生成”。
打开Windows命令提示符(cmd)。 转到OPENCV_PATH / build目录并运行此命令 1
cmake.exe --build . --config Release --target INSTALL
如步骤5所述,再次打开CMake GUI。
在搜索框中搜索“ python” 取消选中INSTALL_PYTHON_EXAMPLES,BUILD_opencv_python3和BUILD_opencv_python2 点击配置 点击生成 现在在Windows命令提示符下 转到OPENCV_PATH / build目录并运行此命令
1
cmake.exe --build . --config Debug --target INSTALL
现在我们已经编译了OpenCV,我们将了解如何使用CMake测试OpenCV项目。
答案 1 :(得分:0)
opencv-4.3.0.zip
和opencv_contrib-4.3.0.zip.
解压缩。 opencv_contrib-4.3.0\modules.
,复制名为xfeatures2d
的文件夹。打开opencv-4.3.0\modules
,然后粘贴刚刚复制的文件夹(xfeatures2d
)Build45
)的文件路径opencv-4.3.0.
的文件路径configure.
将会出现选择。xfeatures2d
并选中“ Build_opencv_xfeatures2d”框configure
。 (仔细检查您是否已正确完成此操作:cmake gui中还有第二个框提供了构建详细信息。您应该看到Non-free algorithms: YES
。Generate
。cd ~/opencv-master/build45
)cmake .
make
sudo make install
python3
import cv2
sift = cv2.xfeatures2d.SIFT_create()
import cv2
print cv2.getBuildInformation()
import cv2
funcs = dir(cv2)
for f in funcs:
... print(f)
此外,如果您担心专利侵权,请在此处进行讨论:https://www.reddit.com/r/computervision/comments/ba1l8g/according_to_this_the_patent_on_sift_was_due_to/