尽管设置了标志 DOPENCV_ENABLE_NONFREE=ON,但运行 opencv 获得专利的 SIFT 和 SURF 的问题

Posted

技术标签:

【中文标题】尽管设置了标志 DOPENCV_ENABLE_NONFREE=ON,但运行 opencv 获得专利的 SIFT 和 SURF 的问题【英文标题】:Problem to run opencv patented SIFT and SURF although flag DOPENCV_ENABLE_NONFREE=ON is set 【发布时间】:2021-08-04 22:41:28 【问题描述】:

我目前正在研究 opencv 版本。 4.5.1 我想使用 SIFT 和 SURF,但我遇到了众所周知的问题,即它们已获得专利。我已经知道在4.5.1 下可以使用标志DOPENCV_ENABLE_NONFREE=ONDBUILD_opencv_xfeatures2d=ON。但是当我对 cmake 使用以下命令时

cmake -DOPENCV_EXTRA_MODULES_PATH=home/myname/opencv_build/opencv_contrib/modules/xfeatures2d/src -DOPENCV_ENABLE_NONFREE=ON -DBUILD_opencv_xfeatures2d=ON .

我遇到了以下问题:

-- The C compiler identification is GNU 9.3.0
-- The CXX compiler identification is GNU 9.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: /usr/local (found version "4.5.1") 
-- OpenCV library status:
--     config: /usr/local/lib/cmake/opencv4
--     version: 4.5.1
--     libraries: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_gapi;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio;opencv_aruco;opencv_bgsegm;opencv_bioinspired;opencv_ccalib;opencv_datasets;opencv_dnn_objdetect;opencv_dnn_superres;opencv_dpm;opencv_face;opencv_freetype;opencv_fuzzy;opencv_hfs;opencv_img_hash;opencv_intensity_transform;opencv_line_descriptor;opencv_mcc;opencv_optflow;opencv_phase_unwrapping;opencv_plot;opencv_quality;opencv_rapid;opencv_reg;opencv_rgbd;opencv_saliency;opencv_shape;opencv_stereo;opencv_structured_light;opencv_superres;opencv_surface_matching;opencv_text;opencv_tracking;opencv_videostab;opencv_wechat_qrcode;opencv_xfeatures2d;opencv_ximgproc;opencv_xobjdetect;opencv_xphoto
--     include path: /usr/local/include/opencv4
-- Configuring done
-- Generating done
CMake Warning:
  Manually-specified variables were not used by the project:

    BUILD_opencv_xfeatures2d
    OPENCV_ENABLE_NONFREE
    OPENCV_EXTRA_MODULES_PATH


-- Build files have been written to: /home/myname/Dokumente/test/project

clion中的输出是:

terminate called after throwing an instance of 'cv::Exception'
  what():  OpenCV(4.5.1-dev) /home/myname/opencv_build/opencv_contrib/modules/xfeatures2d/src/surf.cpp:1027: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'create'

几个小时以来,我一直在拼命尝试让程序运行并执行算法(SIFT、SURF),现在已经到了我(非常非常不情愿地)想要降级 opencv 的地步。 (我同时需要这个版本的 opencv 用于另一个项目)。

有没有人告诉我如何让 5.4.1 下的算法在这里工作。否则,我应该使用哪个 OpenCV 版本 (c++) 才能毫无问题地使用 SIFT 和 SURF。在使用 c++ 的情况下,我没有找到任何可以降级版本的方法。我发现的只是python的情况。

非常感谢您的帮助!!!

【问题讨论】:

您使用的选项应该在构建 OpenCV 本身时启用,而不是在构建项目时启用。 哦,这很尴尬。非常感谢! 【参考方案1】:

使用SIFT算法无需重新构建OpenCV,使用4.4.0以上版本即可。

发布亮点:

SIFT (Scale-Invariant Feature Transform) algorithm has been moved to the main repository (patent expired)

对于 python:

pip install opencv-python==4.4.0.46

并直接访问它(no more xfeatures2d

import cv2
sift = cv2.SIFT_create()

【讨论】:

【参考方案2】:

使用以下命令构建 OpenCV:

cmake -D CMAKE_BUILD_TYPE=Release \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D OPENCV_EXTRA_MODULES_PATH=path/to/opencv_contrib/modules \
      -D OPENCV_ENABLE_NONFREE=ON \
      path/to/opencv

【讨论】:

这个命令(在正确的目录中......我真丢脸)工作...... cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_opencv_xfeatures2d=ON -DOPENCV_ENABLE_NONFREE=ON -DOPENCV_EXTRA_MODULES_PATH=。 ./../opencv_contrib/modules/ ..

以上是关于尽管设置了标志 DOPENCV_ENABLE_NONFREE=ON,但运行 opencv 获得专利的 SIFT 和 SURF 的问题的主要内容,如果未能解决你的问题,请参考以下文章

C:尽管添加了 `-ldl` 标志,但未定义对 `dlopen`/`dlsym` 的引用

tsc compile in React (create-react-app) 需要显式编译标志,尽管我在 tsconfig.json 中设置了它们

如何在 C 中实现无锁共享标志?

没有从 AppDelegate 设置 RootViewController?

标志 - 检查是不是设置了位并且仅设置了这些位

没有设置安全标志和 HttpOnly 标志的 Cookie