-3

I am using visual studio 2017. Opencv and opencv verison of 4.2.0 is installed and files are generated using cmake. xfeatured2d420.lib is linked with compiler. And also #include "opencv2/xfeatures2d.hpp" #include "opencv2/xfeatures2d/nonfree.hpp" included. Extracting features using xfeatures2d::Sift giving me memory error. I need to compute sift keypoints from two images.

alexander
  • 7
  • 5
  • cv::Ptr f2d = xfeatures2d::SIFT::create(); Memory Error at this point std::vector keypoints_1, keypoints_2; f2d->detect(frame, keypoints_1); f2d->detect(frame2, keypoints_2); – alexander Oct 23 '21 at 12:22
  • your post needs to include a [mre]. *edit* your question. make sure to format/style the code as code. don't leave it as text. – Christoph Rackwitz Oct 23 '21 at 12:34
  • Please provide enough code so others can better understand or reproduce the problem. – Community Oct 23 '21 at 13:25
  • Mat img_1 = imread("C:/Users/Dan/Desktop/0.jpg", 1); Mat img_2 = imread("C:/Users/Dan/Desktop/0.jpg", 1); cv::Ptr f2d = xfeatures2d::SIFT::create(); std::vector keypoints_1, keypoints_2; f2d->detect(img_1, keypoints_1); f2d->detect(img_2, keypoints_2); Mat descriptors_1, descriptors_2; f2d->compute(img_1, keypoints_1, descriptors_1); f2d->compute(img_2, keypoints_2, descriptors_2); BFMatcher matcher; std::vector< DMatch > matches; matcher.match(descriptors_1, descriptors_2, matches); – alexander Oct 23 '21 at 13:44
  • I unable to post whole code due to lenght. I am using this example https://stackoverflow.com/questions/38971426/how-to-draw-detected-object-with-sift-features-on-opencv-3-1 – alexander Oct 23 '21 at 13:45
  • I tried alot to execute this code. But memory error comes even at start of creating SIFT (cv::Ptr f2d = xfeatures2d::SIFT::create();). I tried to lower down opencv but I was not succesful in generating files using cmake. So I used open 4.2.1 and build and generate files. Also link all libraries. – alexander Oct 23 '21 at 13:47
  • I follow these instructions to install opencv and oponcv contributions(https://stackoverflow.com/questions/27533203/how-do-i-use-sift-in-opencv-3-0-with-c). Just didnt execute (g++ -std=c++11 main.cpp `pkg-config --libs --cflags opencv` -lutil -lboost_iostreams -lboost_system -lboost_filesystem -lopencv_xfeatures2d -o surftestexecutable). – alexander Oct 23 '21 at 13:59
  • Please take the [tour] and read the guide on [ask] good questions on Stack Overflow – Christoph Rackwitz Oct 23 '21 at 15:20

1 Answers1

-1
Mat img_1 = imread("C:/Users/Dan/Desktop/0.jpg", 1);   
Mat img_2 = imread("C:/Users/Dan/Desktop/0.jpg", 1);
cv::Ptr<Feature2D> f2d = xfeatures2d::SIFT::create(); 
std::vector<KeyPoint> keypoints_1, keypoints_2; 
f2d->detect(img_1, keypoints_1); 
f2d->detect(img_2, keypoints_2); 
Mat descriptors_1, descriptors_2; 
f2d->compute(img_1, keypoints_1, descriptors_1); 
f2d->compute(img_2, keypoints_2, descriptors_2); 
BFMatcher matcher; 
std::vector< DMatch > matches; matcher.match(descriptors_1, 
descriptors_2, matches); 
vector<cv::DMatch> good_matches;
for (int i = 0; i < matches.size(); ++i)
{
    const float ratio = 0.8; 
    if (matches[i][0].distance < ratio * matches[i] 
 [1].distance)
                {
                good_matches.push_back(matches[i][0]);
                }
    }

vector<Point2f> points1, points2;
for (int i = 0; i < good_matches.size(); i++)
    {
            //-- Get the keypoints from the good matches
             
        points1.push_back(keypoints_1[good_matches[i].queryIdx].pt);
             
        points2.push_back(keypoints_2[good_matches[i].trainIdx].pt);
    }

        /* Find Homography */
Mat H = findHomography(Mat(points2), Mat(points1), RANSAC);
alexander
  • 7
  • 5
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Oct 23 '21 at 14:29
  • this appears to be an amendment to your question, not an answer. please review the [tour] to learn how this site works. – Christoph Rackwitz Oct 23 '21 at 15:22
  • This example does not compile and is incorrect. – Sailanarmo Jul 25 '22 at 14:16