我试图从两张图片中获取匹配功能点,以便进一步处理。我通过引用FLANN的SURF特征匹配的example编写了以下代码,但是在ORB中。
这是代码:
#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;
}
但这引发了一个异常错误:
Project1.exe中0x00007FF97D3B9E08处的未处理异常:Microsoft C ++异常:cv ::内存位置0x0000009E5D4FE3B0处的异常。发生
可能是我的代码充满了废话,如果有人可以帮助我解决这个问题,那就表示赞赏。
答案 0 :(得分:1)
ORB是一个二进制描述符,需要一个不同的(汉明距离)匹配器:
Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create("BruteForce-Hamming");
(取自:https://docs.opencv.org/3.4.1/dc/d16/tutorial_akaze_tracking.html)
答案 1 :(得分:1)
im_left = imread("im_left.png", IMREAD_GRAYSCALE);
im_left = imread("im_right.png", IMREAD_GRAYSCALE);
您已经两次将图像读入同一变量。