Android OpenCV:绘图与feature2d匹配 [英] Android OpenCV: drawing matches with feature2d
问题描述
我无法使用此功能。基本上我正在进行特征检测并与参考图像匹配。我想在输入图像上叠加匹配的功能。这是我的代码:
I can't get this function to work. Basically I am doing feature detection and matching with a reference image. I want to overlay the matched features on top of my input image. Here is my code:
public Mat startProcessing(Mat inputImage) {
Imgproc.cvtColor(inputImage, rgb, Imgproc.COLOR_GRAY2RGB);
myFeatures.detect(rgb, keypoints);
descriptorExtractor.compute(inputImage, keypoints, imageDescriptors);
descriptorMatcher.match(templateDescriptors, imageDescriptors, matches);
Features2d.drawMatches(rgb, keypoints, templateImage, templateKeypoints, matches, rgb);
Imgproc.cvtColor(rgb, outputImage, Imgproc.COLOR_RGB2RGBA);
return outputImage;
}
这是Features2d.drawMatches,这是特别的问题。根据我得到的Android错误,一些维度没有排队。说实话,我甚至不确定 drawMatches
应该如何在Android上运行,因为在任何地方都没有文档。
It's Features2d.drawMatches which is specifically the problem. According to the Android error I've gotten, some dimensions aren't lining up. Truth be told, I'm not even sure how drawMatches
is supposed to work on Android because there's no documentation anywhere.
我希望能够做的是在inputImage之上绘制匹配项。我已经 Feature2d.drawKeypoints
工作,但我不确定如何将 MatOfDMatch匹配
转换为一个 MatOfKeypoint
对象。此外,我甚至不确定MatOfDMatch是如何工作的 - 它是否与描述符对应的内部有一些关联性?
What I want to be able to do is draw the matches on top of the inputImage. I've gotten Feature2d.drawKeypoints
to work, but I'm unsure how I would go about converting MatOfDMatch matches
to a MatOfKeypoint
object. Also I'm not even sure if that's how the MatOfDMatch works - doesn't it have some associativity inside of it corresponding to the descriptors?
对于到处都是抱歉,我很难在Android上使用OpenCV。那里的C ++文档很好,但Android材料的方式却很少。谢谢你的帮助!
Sorry for being all over the place, I'm having a really hard time using OpenCV with Android. The C++ documentation out there is good, but there's little in the way of Android materials. Thanks for any help!
推荐答案
我注意到的第一件事是你将图像从一个色彩空间转换为另一个色彩空间。令人困惑的是一点点。如果要在灰度图像上绘制匹配项,则无需执行此图像转换。
另外,你正在检测RGB图像上的关键点,然后从原始图像中提取描述符(我可以看到它是灰度)
First thing that I've noticed is that you are converting images from one color space to another. It's confusing a little bit. If you want to draw matches on greyscale images, it is not necessary to perform this image conversion. Other thing, you are detecting keypoints on RGB image and then extracting descriptors from original image(as I can see it is greyscale)
另外我建议你如果图像属于同一类型,请检查函数内部。只需在log inputImage
对象中打印,看看它们是否都是 CV_8UC3
类型或等效类型。基本上你的代码应该是这样的:
Also I suggest you to check inside of your function if images are of the same type. Just print in log inputImage
object and see if both are of type CV_8UC3
or equivalent. Basically your code should be like this:
Mat imageOut = inputImage.clone();
Features2d.drawMatches(inputImage, keypoints, templateImage, templateKeypoints, matches, imageOut);
Highgui.imwrite("result_match.jpeg", imageOut);
回答另一个问题:
问:我不确定如何将 MatOfDMatch
匹配转换为 MatOfKeypoint
对象。
答:您不需要这样做,因为 drawMatches
函数接收输入图像的 MatOfKeypoint
以及的模板图像。然后,当您传递 MatOfDMatch
时,它会在匹配的接收点之间绘制匹配。
Q:I'm unsure how I would go about converting MatOfDMatch
matches to a MatOfKeypoint
object.
A:You do not need to do it, because drawMatches
function receives MatOfKeypoint
of input image and also of template image. Then when you passing MatOfDMatch
it draws matches between matched received kypoints.
问:我甚至不确定 MatOfDMatch
是否有效 - 是不是有一些它内部的关联性对应于描述符?
答:是的。如果你要做 matches.toList(0).queryIdx
和 matches.toList(0).trainIdx
你会得到索引 inputImage
的关键点,它匹配 templateImage
的第一场比赛的关键点。
Q:Also I'm not even sure if that's how the MatOfDMatch
works - doesn't it have some associativity inside of it corresponding to the descriptors?
A:Yes it have. If you will do matches.toList(0).queryIdx
and matches.toList(0).trainIdx
you will get the index of inputImage
's keypoint, which matches with templateImage
's keypoint of the first match.
这篇关于Android OpenCV:绘图与feature2d匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!