OpenCV SIFT & SURF [closed]

asked 2019-05-07 07:24:16 -0600

blessme29 gravatar image

updated 2019-05-07 07:49:13 -0600

LBerger gravatar image

Hello I have some question related to the SIFT and SURF I installed opencv contrib via VCPKG (https://github.com/microsoft/vcpkg) for visual studio 2017 C++ But when I tried to run it, I got error like this :

OpenCV(3.4.3) Error: 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 cv::xfeatures2d::SIFT::create, file C:\vcpkg\buildtrees\opencv\src\3.4.3-98dbf13329\modules\xfeatures2d\src\sift.cpp, line 1207

Is there anyone had same problem with me and solved this problem?

This is my code :

#include "pch.h"
#include <opencv2/ximgproc.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/features2d/features2d.hpp>
#include <opencv2/xfeatures2d.hpp>
#include <opencv2/xfeatures2d/nonfree.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/calib3d/calib3d.hpp>
#include <iostream>
#include <stdio.h>
#include <chrono>
using namespace std;
using namespace cv;
using namespace cv::xfeatures2d;
int main()
{
    Mat img_1 = imread("a6.jpg", IMREAD_GRAYSCALE);
    Mat img_2 = imread("a7.jpg", IMREAD_GRAYSCALE);

    if (!img_1.data || !img_2.data)
    {
        std::cout << " --(!) Error reading images " << std::endl; return -1;
    }

    //-- Step 1: Detect the keypoints using SURF Detector
    int minHessian = 400;

    Ptr<SIFT> detector = xfeatures2d::SIFT::create(minHessian);


    std::vector<KeyPoint> keypoints_1, keypoints_2;

    detector->detect(img_1, keypoints_1);
    detector->detect(img_2, keypoints_2);

    //-- Draw keypoints
    Mat img_keypoints_1; Mat img_keypoints_2;

    drawKeypoints(img_1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT);
    drawKeypoints(img_2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT);

    //-- Show detected (drawn) keypoints
    imshow("Keypoints 1", img_keypoints_1);
    imshow("Keypoints 2", img_keypoints_2);

    waitKey(0);

    return 0;
}
edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by berak
close date 2019-05-07 08:28:25.702244

Comments

Answer to your problem is in error message : Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library

LBerger gravatar imageLBerger ( 2019-05-07 07:50:15 -0600 )edit

opencv does not maintain any vcpkg repos (we cannot help with that).

but again, you have to build from src, using cmake -DOPENCV_ENABLE_NONFREE=ON

berak gravatar imageberak ( 2019-05-07 08:30:44 -0600 )edit