用了ORB那么久,今天第一次将256bit的描述子打印出来,直观看到了match的汉明距离。
上代码:#include
#include
#include
#include
#include
#include
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 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 matches,good;
bf.match(descriptors, descriptors1, matches);
for (size_t i = 0; i
{
if (matches[i].distance
good.push_back(matches[i]);
}
cout <
Mat imagem;
drawMatches(image, keypoints, image1, keypoints1, good,imagem);
imshow("1", imagem);
for (size_t i = 0; i
{
cout <
for (int j = 0; j
{
cout <( (int)descriptors.at(good[i].queryIdx, j) ) <
cout <( (int)descriptors1.at(good[i].trainIdx, j) ) <
}
cout <
}
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版权协议,转载请附上原文出处链接及本声明。
#转载请注明出处 www.skcircle.com 《少有人走的路》勇哥的工业自动化技术网站。如果需要本贴图片源码等资源,请向勇哥索取。
收藏 | 0点赞 | 0打赏作者