I am currently trying to use OpenCV's SiftFeatureDetector. However, this happens: Click This Link For Image
I saw that I needed the nonfree files. This is where i got my files from:
features2d.hpp: sourceforge.net/p/emgucv/opencv/ci/3ad471d9c187b6509ca4aab439290bc76c7a258f/tree/modules/nonfree/include/opencv2/nonfree/features2d.hpp
nonfree.hpp: sourceforge.net/p/emgucv/opencv/ci/3ad471d9c187b6509ca4aab439290bc76c7a258f/tree/modules/nonfree/include/opencv2/nonfree/nonfree.hpp
These are my imports: Click This Link For Image
Can somebody please tell me what's the problem?
You are getting files from EmguCV site. EmguCV is a wrapper around OpenCV developed for .net framework. If you are going to use OpenCV with c++ then you should use OpenCV library and header files downloadable from: http://opencv.org.
It seems that SIFT moved out of default install of OpenCV from version 3.0
. So the answer depends on the version of OpenCV you are using.
NOTE: If you don't want to be bothered with building OpenCV yourself, you should consider using 2.4.13.2
, or version less than 3.0
.
Tested on Windows 10 with Visual Studio 2015.
You can download prebuilt library from this link. The prebuilt library includes SIFT. (In my case, since I'm on Windows, I've used opencv-2.4.13.2-vc14.exe
) You can use SIFT like the following code.
#include <opencv2/opencv.hpp>
#include <opencv2/nonfree/features2d.hpp>
int main(int argc, const char* argv[])
{
const cv::Mat input = cv::imread("D:/lenna.png", 0); //Load as grayscale
// Detect
cv::SiftFeatureDetector detector;
std::vector<cv::KeyPoint> keypoints;
detector.detect(input, keypoints);
// Add results to image and save.
cv::Mat output;
cv::drawKeypoints(input, keypoints, output);
cv::imwrite("D:/lenna_sift.jpg", output);
return 0;
}
original image / feature detected image
(copied this minimal example from here)
You can download prebuilt library for this version from this link, but this version doesn't include SIFT as a default installed feature. (I've checked opencv-3.2.0-vc14.exe
and it doesn't have it) It seems that the OpenCV community decided to remove patented algorithms like SIFT and SURF from default install starting from version 3.0
(link). To use these, you have to download the opencv and opencv_contrib source code and build the library yourself. You have to configure your build settings so you can build with SIFT enabled. Then you can do SIFT like follows.
#include <opencv2/opencv.hpp>
#include <opencv2/xfeatures2d.hpp>
int main(int argc, const char* argv[])
{
const cv::Mat input = cv::imread("D:/lenna.png", 0); //Load as grayscale
// Detect
cv::Ptr<cv::Feature2D> f2d = cv::xfeatures2d::SiftFeatureDetector::create();
std::vector<cv::KeyPoint> keypoints;
f2d->detect(input, keypoints);
// Add results to image and save.
cv::Mat output;
cv::drawKeypoints(input, keypoints, output);
cv::imwrite("D:/lenna_sift.jpg", output);
return 0;
}
original image / feature detected image
I expect using SIFT with other versions before 3.0
should be same as 2.4.13.2
, and version including and after 3.0
to be same as 3.2
. If it's not, please let me know so I can improve this post.