Opened 4 years ago

Closed 4 years ago

#61415 closed defect (duplicate)

opencv +contrib: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration

Reported by: ifernandolopez (Fernando López Hernández) Owned by:
Priority: Normal Milestone:
Component: ports Version:
Keywords: Cc:
Port: opencv

Description (last modified by mf2k (Frank Schima))

opencv compile properly with the contrib variant:

sudo port install opencv @+java+python37+contrib

However, the library fails in runtime when you aim to use SURF/SIFT with this this very clarifying message:

opencv_contrib-3.4.10/modules/xfeatures2d/src/surf.cpp:1029: 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'

Is it possible to ask the maintainer to add this CMake flag to the contrib variant:

-D OPENCV_ENABLE_NONFREE=ON

PS: The library compiles fine and does not fail until you use a non free feature in runtime. I am attaching a source code for the maintainer that demonstrates it:

#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/xfeatures2d/nonfree.hpp>

int main(int argc, const char * argv[]) {
  cv::Mat im1 = cv::imread("view1.jpg", CV_LOAD_IMAGE_COLOR);
  cv::Mat im2 = cv::imread("view2.jpg", CV_LOAD_IMAGE_COLOR);
  if (im1.empty() || im2.empty()) {
    std::cout << "Error loading image" << std::endl;
    return 1;
  }
  // Define features detector
  cv::Ptr<cv::Feature2D> detector; // Generic detectior
  int hessian_threshold = 100;
  detector = cv::xfeatures2d::SURF::create(hessian_threshold);
  // Detect the keypoints
  std::vector<cv::KeyPoint> keypoints1, keypoints2;
  detector->detect(im1, keypoints1);
  detector->detect(im2, keypoints2);
  // Compute the keypoints descriptors
  cv::Mat descriptors1, descriptors2;
  detector->compute(im1, keypoints1, descriptors1);
  detector->compute(im2, keypoints2, descriptors2);
  // Compute the matches
  cv::BFMatcher matcher(cv::NORM_L2);
  std::vector<cv::DMatch> matches;
  matcher.match(descriptors1, descriptors2, matches);
  // Sort the 25th best matches at the beggining, and remove the rest
  std::nth_element(matches.begin(), matches.begin()+25, matches.end());
  matches.erase(matches.begin()+25, matches.end());
  // Show results
  cv::Mat im_matches;
  cv::drawMatches(im1, keypoints1, im2, keypoints2, matches, im_matches);
  cv::imshow("Matches", im_matches);
  cv::waitKey(0);
  return 0;
}

Here I am also attaching related information in Homebrew:

https://www.pyimagesearch.com/2018/08/17/install-opencv-4-on-macos/

Change History (4)

comment:1 Changed 4 years ago by mf2k (Frank Schima)

Keywords: opencv contrib removed

comment:2 Changed 4 years ago by mf2k (Frank Schima)

Description: modified (diff)

comment:3 Changed 4 years ago by mf2k (Frank Schima)

Description: modified (diff)

comment:4 in reply to:  description Changed 4 years ago by ryandesign (Ryan Carsten Schmidt)

Resolution: duplicate
Status: newclosed
Summary: The opencv package needs to be compile with the OPENCV_ENABLE_NONFREE CMake flagopencv +contrib: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration

Replying to ifernandolopez:

Is it possible to ask the maintainer to add this CMake flag to the contrib variant:

As you can see by running port info opencv, the port does not have a maintainer. Anyone may submit a pull request to make changes.

Duplicate of #57640.

Note: See TracTickets for help on using tickets.