KeyPoint 和 point2f相互转换

KeyPoint 转point2f

void KeyPointsToPoints(vector<KeyPoint> kpts, vector<Point2f> &pts)
{
	for (int i = 0; i < kpts.size(); i++) {
		pts.push_back(kpts[i].pt);
	}
}

point2f 转KeyPoint

void PointsToKeyPoints(vector<Point2f>pts,vector<KeyPoint> &kpts)
{
	for (size_t i = 0; i < pts.size(); i++) {
		kpts.push_back(KeyPoint(pts[i], 1.f));
	}
}
分析代码://RANSAC算法 int main() { Mat img_object = imread("./data/101.png", IMREAD_GRAYSCALE); Mat img_scene = imread("./data/100.png", IMREAD_GRAYSCALE); if (img_object.empty() || img_scene.empty()) { cout << "Could not open or find the image!\n" << endl; return -1; } //-- Step 1: Detect the keypoints using SURF Detector, compute the descriptors int minHessian = 800; // default: 400 Ptr<SURF> surf = SURF::create(800); std::vector<KeyPoint> keypoints_object, keypoints_scene; Mat descriptors_object, descriptors_scene; surf->detectAndCompute(img_object, noArray(), keypoints_object, descriptors_object); surf->detectAndCompute(img_scene, noArray(), keypoints_scene, descriptors_scene); //-- Step 2: Matching descriptor vectors with a FLANN based matcher // Since SURF is a floating-point descriptor NORM_L2 is used Ptr<DescriptorMatcher> matcher = DescriptorMatcher::create(DescriptorMatcher::FLANNBASED); std::vector< std::vector<DMatch> > knn_matches; matcher->knnMatch(descriptors_object, descriptors_scene, knn_matches, 2); //-- Filter matches using the Lowe's ratio test const float ratio_thresh = 0.75f; std::vector<DMatch> good_matches; for (size_t i = 0; i < knn_matches.size(); i++) { if (knn_matches[i][0].distance < ratio_thresh * knn_matches[i][1].distance) { good_matches.push_back(knn_matches[i][0]); } } //-- Draw matches Mat img_matches; drawMatches(img_object, keypoints_object, img_scene, keypoints_scene, good_matches, img_matches, Scalar::all(-1), Scalar::all(-1), std::vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS); //-- Localize the object std::vector<Point2f> obj; std::vector<Point2f> scene; for (size_t i = 0; i < good_matches.size(); i++) { //-- Get the keypoints from the good matches obj.push_back(keypoints_object[good_matches[i].queryIdx].pt);
最新发布
03-31
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值