C++ 未实现 OpenCV SURF 功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11175794/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 14:55:08  来源:igfitidea点击:

OpenCV SURF function is not implemented

c++visual-c++opencvimplementationsurf

提问by rotating_image

When I try to run the sample find_obj.cppor any OpenCV SURF program I get the following error in command prompt while executing the code. The project builds without errors and warnings. I am using VS2011 beta, OpenCV 2.4 and windows7.

当我尝试运行示例find_obj.cpp或任何 OpenCV SURF 程序时,我在执行代码时在命令提示符中收到以下错误。项目构建时没有错误和警告。我使用的是 VS2011 beta、OpenCV 2.4 和 windows7。

Error message:

错误信息:

OpenCV Error: The function/feature is not implemented < OpenCV was built without SURF support> in unknown function,file ..\..\..\src\opencv\modules\legacy\src\features2d.cpp, line 77

I tried to build the OpenCV 2.4 again using Cmake and then VS2011 in debug mode and then added the lib paths in the IDE, but still no result.

我尝试使用 Cmake 再次构建 OpenCV 2.4,然后在调试模式下使用 VS2011,然后在 IDE 中添加 lib 路径,但仍然没有结果。

How can I fix that?

我该如何解决?

    #include <opencv2/objdetect/objdetect.hpp>
    #include <opencv2/features2d/features2d.hpp>
    #include <opencv2/core/core.hpp>
    #include <opencv2/highgui/highgui.hpp>
    #include <opencv2/legacy/legacy.hpp>
    #include <opencv2/legacy/compat.hpp>
    #include <opencv2/flann/flann.hpp>
    #include <opencv2/calib3d/calib3d.hpp>
    #include <opencv2/nonfree/features2d.hpp>
    #include <opencv2/nonfree/nonfree.hpp>

using namespace std;
using namespace cv;
int main()
{
    cv::initModule_nonfree();//THIS LINE IS IMPORTANT   

   IplImage *image1 = cvLoadImage("C:\SURF\1.jpg"); 
    IplImage *image2 = cvLoadImage("C:\SURF\2.jpg");

    CvMemStorage* memoryBlock = cvCreateMemStorage();
    CvSeq* image1KeyPoints;
    CvSeq* image1Descriptors;
    CvSeq* image2KeyPoints;
    CvSeq* image2Descriptors;

    // Only values with a hessian greater than 500 are considered for keypoints
   CvSURFParams params = cvSURFParams(500, 1);
   cvExtractSURF(image1, 0, &image1KeyPoints, &image1Descriptors, memoryBlock, params);
   cvExtractSURF(image2, 0, &image2KeyPoints, &image2Descriptors, memoryBlock, params);

   return 0;
}

采纳答案by ArtemStorozhuk

Taken from this answer(why don't you google your question before asking?):

摘自这个答案(为什么不在提问之前先用谷歌搜索一下?):

The SIFT and SURF code was moved in OpenCV v2.4 to a new module called nonfree. Make sure you are linking (DLL in Windlows) to it. In linux this library is called libopencv_nonfree.so.

SIFT 和 SURF 代码在 OpenCV v2.4 中被移动到一个名为 nonfree. 确保您正在链接(Windlows 中的 DLL)到它。在 linux 中,这个库被称为libopencv_nonfree.so.

回答by erlingmusan

It's not a bug. SURF is located in nonfree module. To use it you should initialize nonfree module:

这不是一个错误。SURF 位于非自由模块中。要使用它,您应该初始化非自由模块:

    #include <opencv2/nonfree/nonfree.hpp> 
    ... 
    cv::initModule_nonfree();

回答by fay

Recently, I am learning the SURF. For this question you can add the opencv_nonfree240d.lib and opencv_nonfree240.lib to your project's lib path.

最近,我正在学习 SURF。对于这个问题,您可以将 opencv_nonfree240d.lib 和 opencv_nonfree240.lib 添加到项目的 lib 路径中。

回答by jeremy_rutman

For ubuntu the script at https://help.ubuntu.com/community/OpenCVcan be modified for nonfree surf/sift use by adding

对于 ubuntu,https://help.ubuntu.com/community/OpenCV 上的脚本 可以通过添加

libopencv_nonfree

libopencv_nonfree

to the end of the sudo apt-get command, and

到 sudo apt-get 命令的末尾,以及

-D BUILD_opencv_nonfree=ON

-D BUILD_opencv_nonfree=ON

to the end of the cmake command. It only worked for me after uninstalling everything I could find dealing with opencv from the software center. Incidentally the software center also had an opencv nonfree library, "libopencv-nonfree2.4" which didn't seem to help matters. I am not an expert in such stuff so I don't know if what I did is 100% right, but it allows commands such as

到 cmake 命令的末尾。它仅在卸载我可以从软件中心找到处理 opencv 的所有内容后才对我有用。顺便说一下,软件中心还有一个 opencv 非自由库,“libopencv-nonfree2.4”,它似乎没有帮助。我不是这方面的专家,所以我不知道我所做的是否 100% 正确,但它允许诸如

surf = cv2.SURF(400)

冲浪 = cv2.SURF(400)

and

keypoints = surfDetector.detect(im)

关键点 = surfDetector.detect(im)

to run which hadnt previously (the first caused a 'not found' type error while the second caused a segfault).

运行以前没有的(第一个导致“未找到”类型错误,而第二个导致段错误)。

The version of opencv.sh which allowed me to use nonfree surf/sift pasted to http://pastebin.com/sQzDdx5i
The version that is working now is opencv-2.4.9 but possibly this would work for other versions as the script seems to be somewhat agnostic as do the lib names.

允许我使用粘贴到http://pastebin.com/sQzDdx5i
的非自由冲浪/筛选的 opencv.sh版本现在正在运行的版本是 opencv-2.4.9 但可能这适用于其他版本,因为脚本似乎与 lib 名称一样有点不可知论。