OpenCV C++;矢量匹配到C# 我在C++中使用OpenCV,编写了一个使用SURF检测器检测关键点的函数,并使用蛮力匹配器 BFMachter < /C>来搜索匹配。
以下是我代码的相关部分:OpenCV C++;矢量匹配到C# 我在C++中使用OpenCV,编写了一个使用SURF检测器检测关键点的函数,并使用蛮力匹配器 BFMachter < /C>来搜索匹配。,c#,c++,opencv,vector,type-conversion,C#,C++,Opencv,Vector,Type Conversion,以下是我代码的相关部分: std::vector< DMatch > FeatureDetection(char* source, char* itempl, int x, int y ,int width, int height) // Features2D + Homography to find a known object { /// Load image and template Mat img_gray = imread( source, CV_LOAD_IMAG
std::vector< DMatch > FeatureDetection(char* source, char* itempl, int x, int y ,int width, int height) // Features2D + Homography to find a known object
{
/// Load image and template
Mat img_gray = imread( source, CV_LOAD_IMAGE_GRAYSCALE );
img = img_gray(Rect(x, y, width, height));
templ = imread( itempl, CV_LOAD_IMAGE_GRAYSCALE );
//-- Step 1: Detect the keypoints using SURF Detector
int minHessian = 400;
SurfFeatureDetector detector( minHessian );
std::vector<KeyPoint> keypoints_1, keypoints_2;
detector.detect( templ, keypoints_1 );
detector.detect( img, keypoints_2 );
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat descriptors_1, descriptors_2;
extractor.compute( templ, keypoints_1, descriptors_1 );
extractor.compute( img, keypoints_2, descriptors_2 );
//-- Step 3: Matching descriptor vectors with a brute force matcher
BFMatcher matcher(NORM_L2);
std::vector< DMatch > matches;
matcher.match( descriptors_1, descriptors_2, matches );
return matches;
}
编辑:我需要的是匹配点的列表。我不确定
向量是否匹配,甚至不确定是否包含此信息。要将向量转换为匹配点的向量,请执行以下操作:
vector<Point2f> matched_points1, matched_points2; // these are your points that match
for (int i=0;i<matches.size();i++)
{
// this is how the DMatch structure stores the matching information
int idx1=matches[i].trainIdx;
int idx2=matches[i].queryIdx;
//now use those match indices to get the keypoints, add to your two lists of points
matched_points1.push_back(keypoints_1[idx1].pt);
matched_points2.push_back(keypoints_2[idx2].pt);
}
向量匹配_点1,匹配_点2;//这些是你的匹配点
对于(int i=0;iYou没有回答我如何才能将其发送到C#,但我自己已经解决了。我所需要的只是知道如何访问匹配点。因此,这足以让我接受您的回答。谢谢!您能清楚地说明您是如何获得解决方案的吗?
vector<Point2f> matched_points1, matched_points2; // these are your points that match
for (int i=0;i<matches.size();i++)
{
// this is how the DMatch structure stores the matching information
int idx1=matches[i].trainIdx;
int idx2=matches[i].queryIdx;
//now use those match indices to get the keypoints, add to your two lists of points
matched_points1.push_back(keypoints_1[idx1].pt);
matched_points2.push_back(keypoints_2[idx2].pt);
}