Althaf
Althaf

Reputation: 143

ORB feature matching with FLANN in C++

I'm trying to get the match feature points from two images, for further processing. I wrote the following code by referring an example of a SURF Feature Matching by FLANN, but in ORB.

here is the code:

#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/features2D.hpp"


using namespace cv;
using namespace std;



int main(int argc, char** argv)
{
Mat im_left, im_right;
Mat descriptor_1, descriptor_2;

vector<KeyPoint> keypoints_1, keypoints_2;

im_left = imread("im_left.png", IMREAD_GRAYSCALE);
im_left = imread("im_right.png", IMREAD_GRAYSCALE);

Ptr<ORB> detector = ORB::create();
vector<DMatch> matches;
FlannBasedMatcher matcher;
Ptr<DescriptorExtractor> extractor;


detector->detect(im_right, keypoints_1, descriptor_1);
detector->detect(im_left, keypoints_2, descriptor_2);

matcher.match(descriptor_1, descriptor_2, matches);

Mat img_match;

drawMatches(im_left, keypoints_1, im_right, keypoints_2, matches, img_match);
imshow("Matches", img_match);



waitKey(10000);
return 0;
}

But this throws an exception error saying:

Unhandled exception at 0x00007FF97D3B9E08 in Project1.exe: Microsoft C++ exception: cv::Exception at memory location 0x0000009E5D4FE3B0. occurred

May be my code is full of nonsense, appreciate if someone can help me out on solving this.

Upvotes: 0

Views: 4632

Answers (2)

ArthurOnion
ArthurOnion

Reputation: 31

im_left = imread("im_left.png", IMREAD_GRAYSCALE);
im_left = imread("im_right.png", IMREAD_GRAYSCALE);

You have read images into the same variable twice.

Upvotes: 2

RevJohn
RevJohn

Reputation: 1074

ORB is a binary descriptor and needs a different (Hamming distance) matcher for that:

Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce-Hamming");

(taken from: https://docs.opencv.org/3.4.1/dc/d16/tutorial_akaze_tracking.html)

Upvotes: 2

Related Questions