[MacPorts] #61415: The opencv package needs to be compile with the OPENCV_ENABLE_NONFREE CMake flag
MacPorts
noreply at macports.org
Sun Nov 8 15:48:49 UTC 2020
#61415: The opencv package needs to be compile with the OPENCV_ENABLE_NONFREE CMake
flag
-----------------------------+--------------------
Reporter: ifernandolopez | Owner: (none)
Type: defect | Status: new
Priority: Normal | Milestone:
Component: ports | Version:
Resolution: | Keywords:
Port: opencv |
-----------------------------+--------------------
Description changed by mf2k:
Old description:
> 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/
New description:
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/
--
--
Ticket URL: <https://trac.macports.org/ticket/61415#comment:2>
MacPorts <https://www.macports.org/>
Ports system for macOS
More information about the macports-tickets
mailing list