关于OpenCV的那些事——ORB的brief描述子(256bit)的match心得

用了ORB那么久,今天第一次将256bit的描述子打印出来,直观看到了match的汉明距离。

image.png

上代码:

#include <iostream>
#include <bitset>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/features2d/features2d.hpp>
 
using namespace std;
using namespace cv;
 
int main()
{
	Mat image = imread("t.png");
	Mat image1 = imread("t1.png");
	Mat gray,gray1;
	cvtColor(image, gray, CV_BGR2GRAY);
	cvtColor(image1, gray1, CV_BGR2GRAY);
	ORB orb(1000);
	vector<KeyPoint> keypoints,keypoints1;
	orb.detect(gray, keypoints);
	orb.detect(gray1, keypoints1);
	Mat descriptors, descriptors1;
	orb.compute(gray, keypoints, descriptors);
	orb.compute(gray1, keypoints1, descriptors1);
	BFMatcher bf(NORM_HAMMING);
	vector<DMatch> matches,good;
	bf.match(descriptors, descriptors1, matches);
	for (size_t i = 0; i < matches.size(); ++i)
	{
		if (matches[i].distance < 20)
			good.push_back(matches[i]);
	}
	cout << good.size() << endl <<endl;
	Mat imagem;
	drawMatches(image, keypoints, image1, keypoints1, good,imagem);
	imshow("1", imagem);
	for (size_t i = 0; i < good.size(); ++i)
	{
		cout << "第" << i+1 << "对匹配上的描述子,汉明距离为:" << (int)good[i].distance << endl;
		for (int j = 0; j < 32; j++)
		{
			cout << bitset<8>( (int)descriptors.at<uchar>(good[i].queryIdx, j) ) << "  ";
			cout << bitset<8>( (int)descriptors1.at<uchar>(good[i].trainIdx, j) ) <<endl;
		}
		cout << endl;
	}
	waitKey(0);
	return 0;
}

查看了Mat descriptors的信息,行数为keypoints的值,列数为32,说明type为CV_8U(256/32=8)通道的话就只能是1通道。(PS: 强制转换到CV_32U等均报错)

不同于brief描述子的uchar类型,sift和surf均采用float型。所以ORB(brief)描述子8维,32bytes(256bits),CV_8UC1。SIFT描述子128维,512bytes,CV_32UC4(512*8/32 = 32*4,第一个32表示描述子Mat是32列,第二个32表示float类型)。SURF描述子64维,256bytes,CV_32UC2。(OpenCV里compute的描述子的列数都是32)



————————————————

版权声明:本文为CSDN博主「cc_sunny」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/aptx704610875/java/article/details/51503149



本文出自勇哥的网站《少有人走的路》wwww.skcircle.com,转载请注明出处!讨论可扫码加群:

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

会员中心
搜索
«    2024年3月    »
123
45678910
11121314151617
18192021222324
25262728293031
网站分类
标签列表
最新留言
    热门文章 | 热评文章 | 随机文章
文章归档
友情链接
  • 订阅本站的 RSS 2.0 新闻聚合
  • 扫描加本站机器视觉QQ群,验证答案为:halcon勇哥的机器视觉
  • 点击查阅微信群二维码
  • 扫描加勇哥的非标自动化群,验证答案:C#/C++/VB勇哥的非标自动化群
  • 扫描加站长微信:站长微信:abc496103864
  • 扫描加站长QQ:
  • 扫描赞赏本站:
  • 留言板:

Powered By Z-BlogPHP 1.7.2

Copyright Your skcircle.com Rights Reserved.

鄂ICP备18008319号


站长QQ:496103864 微信:abc496103864