我很难让描述符匹配器工作。我有一个要在视频源的每一帧中查找的模板图像。以下是相关代码:
//the following is done once since the template is static:
templateImage = Utils.loadResource(mContext, R.raw.watch);
detector.detect(rgb, templateKeypoints);
Toast.makeText(mContext,"templateImage:" + templateImage.rows() + "/" + templateImage.cols() + " templateKeypoints:" + templateKeypoints.rows() + "/"
+ templateKeypoints.cols(), Toast.LENGTH_LONG).show();
descriptor.compute(rgb, templateKeypoints, templateDescriptors);
这个 toast 的结果是“templateImage:480/640 templateKeypoints:0/1”所以关键点有 0 行和 1 列...
接下来,在每一帧上运行这段代码:
public Mat featureDetection(Mat inputImage) {
// first image
Mat descriptors1 = new Mat();
MatOfKeyPoint keypoints1 = new MatOfKeyPoint();
detector.detect(inputImage, keypoints1);
descriptor.compute(inputImage, keypoints1, descriptors1);
// second image - COVERED BY templateKeypoints, templateDescriptors
// detector.detect(img2, keypoints2);
// descriptor.compute(img2, keypoints2, descriptors2);
// detector.detect(templateImage, templateKeypoints);
// descriptor.compute(templateImage, templateKeypoints,
// templateDescriptors);
// matcher should include 2 different image's descriptors
Log.d(TAG, "descriptors1.type: " + descriptors1.type() + " / cols: " + descriptors1.cols());
Log.d(TAG, "templateDescriptors.type: " + templateDescriptors.type() + " / cols: " + templateDescriptors.cols());
matcher.match(descriptors1, templateDescriptors, matches);
// output image
Mat outputImg = new Mat();
MatOfByte drawnMatches = new MatOfByte();
// this will draw all matches, works fine
Features2d.drawMatches(inputImage, keypoints1, templateImage, templateKeypoints, matches, outputImg, GREEN, RED, drawnMatches,
Features2d.NOT_DRAW_SINGLE_POINTS);
return inputImage;
}
在我返回任何东西之前它就崩溃了:
(首先记录结果:)
04-27 23:04:53.011: D/FrameProcessing(2225): descriptors1.type: 0 / cols: 32
04-27 23:04:53.011: D/FrameProcessing(2225): templateDescriptors.type: 0 / cols: 0
04-27 23:04:53.011: E/cv::error()(2225): OpenCV Error: Assertion failed (type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U)) in void cv::batchDistance(cv::InputArray, cv::InputArray, cv::OutputArray, int, cv::OutputArray, int, int, cv::InputArray, int, bool), file /home/reports/ci/slave/50-SDK/opencv/modules/core/src/stat.cpp, line 1797
04-27 23:04:53.011: W/dalvikvm(2225): threadid=11: thread exiting with uncaught exception (group=0x413c9930)
04-27 23:04:53.018: E/AndroidRuntime(2225): FATAL EXCEPTION: Thread-207
04-27 23:04:53.018: E/AndroidRuntime(2225): CvException [org.opencv.core.CvException: /home/reports/ci/slave/50-SDK/opencv/modules/core/src/stat.cpp:1797: error: (-215) type == src2.type() && src1.cols == src2.cols && (type == CV_32F || type == CV_8U) in function void cv::batchDistance(cv::InputArray, cv::InputArray, cv::OutputArray, int, cv::OutputArray, int, int, cv::InputArray, int, bool)
04-27 23:04:53.018: E/AndroidRuntime(2225): ]
04-27 23:04:53.018: E/AndroidRuntime(2225): at org.opencv.features2d.DescriptorMatcher.match_1(Native Method)
04-27 23:04:53.018: E/AndroidRuntime(2225): at org.opencv.features2d.DescriptorMatcher.match(DescriptorMatcher.java:437)
04-27 23:04:53.018: E/AndroidRuntime(2225): at com.bigsolve.frameprocessing.FrameProcessing.featureDetection(FrameProcessing.java:114)
所以我认为我的tempateKeypoints
,因此我的templateDescriptors
.
outImage
另外,假设我曾经克服过这个错误,那么and到底是什么drawnMatches
?如果我想在我的 640x480 视频源(的返回值垫)上将潜在匹配项覆盖到我的模板,我featureDetection
会返回outImage
吗?
谢谢。