Home > Back-end >  SIFT algorithm problem in opencv
SIFT algorithm problem in opencv

Time:12-23

Have been using Cmake configured opencv_contrib - 4.1.0, but in the use of SIFT algorithm error will appear when "cannot resolve the external command"

 
#include
#include
#include
#include
#include
//# include & lt; Opencv2 xfeatures2d/nonfree. Hpp>//OpenCV 4.2.0 and later
Using the namespace CV: : xfeatures2d;
Using the namespace CV;
using namespace std;
Int main ()
{
CV: : Mat imageL=CV: : imread (" imgL. BMP ");
CV: : Mat imageR=CV: : imread (" imgR. BMP ");


//method to extract the feature points
//SIFT
//CV: : Ptr Sift=CV: : xfeatures2d: : sift: : create ();
//CV: : Ptr Sift=CV: : sift: : Creat ();//OpenCV 4.4.0 and later
//the ORB
//CV: : Ptr The orb=CV: : the orb: : create ();
//SURF
CV: : Ptr Surf=CV: : xfeatures2d: : surf: : create ();

//feature point
STD: : vector KeyPointL keyPointR;
//to extract the feature points alone
Surf - & gt; Detect (imageL keyPointL);
Surf - & gt; Detect (imageR, keyPointR);

//draw feature point
CV: : Mat keyPointImageL;
CV: : Mat keyPointImageR;
DrawKeypoints (imageL, keyPointL keyPointImageL, CV: : Scalar: : (1), all CV: : DrawMatchesFlags: : DRAW_RICH_KEYPOINTS);
DrawKeypoints (imageR, keyPointR keyPointImageR, CV: : Scalar: : (1), all CV: : DrawMatchesFlags: : DRAW_RICH_KEYPOINTS);

//display window
CV: : namedWindow (" KeyPoints of imageL ");
CV: : namedWindow (" KeyPoints of the imageR ");

//display feature point
CV: : imshow (" KeyPoints of imageL keyPointImageL);
CV: : imshow (" KeyPoints of the imageR, "keyPointImageR);

//feature point matching
CV: : Mat despL despR;
//to extract the feature points and calculate the feature descriptor
Surf - & gt; DetectAndCompute (imageL, CV: : Mat (), keyPointL, despL);
Surf - & gt; DetectAndCompute (imageR, CV: : Mat (), keyPointR, despR);

//Struct for DMatch: query descriptor index, "train" descriptor index, train the image index and short between descriptors.
//int queryIdx - & gt; Is to test the image feature points subscript descriptor (descriptor), as well as corresponding feature point (keypoint descriptors of the subscript,
//int trainIdx - & gt; Is a sample image feature point descriptor subscript, is also the corresponding feature points subscript,
//int imgIdx - & gt; Useful when the sample is more images,
//float short - & gt; On behalf of the pair of matching feature points descriptor (essence is a vector) of Euclidean distance, the smaller the value also means that, the more similar two feature points,
STD: : vector Matches;

//if the flannBased method so desp through orb to different need to convert the type of type
If (despL. Type ()!=CV_32F | | despR. Type ()!=CV_32F)
{
DespL. ConvertTo (despL CV_32F);
DespR. ConvertTo (despR CV_32F);
}

CV: : Ptr The matcher=CV: : DescriptorMatcher: : create (" FlannBased ");
The matcher - & gt; Match (despL despR, matches);

//calculate the maximum distance between the feature points
Double maxDist=0;
For (int I=0; I & lt; DespL. Rows; I++)
{
Double dist=matches [I]. Short;
If (dist & gt; MaxDist)
MaxDist=dist.
}

//select good matching point
STD: : vectorFor (int I=0; I & lt; DespL. Rows; I++)
{
If (matches [I] short & lt; 0.5 * maxDist)
{
Good_matches. Push_back (matches [I]);
}
}



CV: : Mat imageOutput;
CV: : drawMatches (imageL keyPointL, imageR, keyPointR, good_matches, imageOutput);

CV: : namedWindow (" picture of matching ");
CV: : imshow (" picture of matching, "imageOutput);
CV: : waitKey (0);
return 0;
}


Don't know is what reason, so no problem,,,,,,,,,
  • Related