opencv 画orb特征点

画特征点 drawKeypoints 函数

前期准备,读取图像,检测ORB特征点

//读取图像
cv::Mat img_1 = cv::imread(argv[1], CV_LOAD_IMAGE_COLOR);
//创建特征点合集
std::vector<cv::KeyPoint> keypoints_1;
//ORB关键点检测函数
cv::Ptr<cv::FeatureDetector> detector = cv::ORB::create();
//检测ORB特征点
detector->detect(img_1, keypoints_1);

画特征点

//输出图像
Mat outimg1;
//输入影像、关键点、输出影像、颜色、标志
drawKeypoints(img_1, keypoints_1, outimg1, Scalar::all(-1), DrawMatchesFlags::DEFAULT);
//显示影像
imshow("ORB features", outimg1);

drawKeypoints 函数参数为:
image – Source image.
keypoints – Keypoints from the source image.
outImage – Output image. Its content depends on the flags value defining what is drawn in the output image. See possible flags bit values below.
color – Color of keypoints.
flags – Flags setting drawing features. Possible flags bit values are defined by DrawMatchesFlags. See details above in drawMatches .

绘制匹配结果 drawMatches函数

  cv::Mat img_1 = cv::imread(argv[1], CV_LOAD_IMAGE_COLOR);
  cv::Mat img_2 = cv::imread(argv[2], CV_LOAD_IMAGE_COLOR);

//-- 初始化
  std::vector<cv::KeyPoint> keypoints_1, keypoints_2;
  cv::Mat descriptors_1, descriptors_2;
  cv::Ptr<cv::FeatureDetector> detector = cv::ORB::create();
  cv::Ptr<cv::DescriptorExtractor> descriptor = cv::ORB::create();
  cv::Ptr<cv::DescriptorMatcher> matcher = cv::DescriptorMatcher::create("BruteForce-Hamming");

  //-- 第一步:检测 Oriented FAST 角点位置
  detector->detect(img_1, keypoints_1);
  detector->detect(img_2, keypoints_2);

  //-- 第二步:根据角点位置计算 BRIEF 描述子
  descriptor->compute(img_1, keypoints_1, descriptors_1);
  descriptor->compute(img_2, keypoints_2, descriptors_2);

//-- 第三步:对两幅图像中的BRIEF描述子进行匹配,使用 Hamming 距离
  vector<cv::DMatch> matches;
  matcher->match(descriptors_1, descriptors_2, matches);

  //-- 第四步:绘制匹配结果
  Mat img_match;
  drawMatches(img_1, keypoints_1, img_2, keypoints_2, matches, img_match);
  imshow("all matches", img_match);

drawMatches 函数参数:
img1 – First source image.
keypoints1 – Keypoints from the first source image.
img2 – Second source image.
keypoints2 – Keypoints from the second source image.
matches1to2 – Matches from the first image to the second one, which means that keypoints1[i] has a corresponding point in keypoints2[matches[i]] .
outImg – Output image. Its content depends on the flags value defining what is drawn in the output image. See possible flags bit values below.
matchColor – Color of matches (lines and connected keypoints). If matchColor== Scalar::all(-1) , the color is generated randomly.
singlePointColor – Color of single keypoints (circles), which means that keypoints do not have the matches. If singlePointColor==Scalar::all(-1) , the color is generated randomly.
matchesMask – Mask determining which matches are drawn. If the mask is empty, all matches are drawn.
flags – Flags setting drawing features. Possible flags bit values are defined by DrawMatchesFlags. This function draws matches of keypoints from two images in the output image. Match is a line connecting two keypoints (circles). See cv::DrawMatchesFlags.

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值