Android OpenCV descriptorMatcher错误

时间:2013-04-28 06:12:48

标签: java android opencv

我很难让descriptorMatcher工作。我有一个模板图像,我想在视频源的每一帧中查找。以下是相关代码:

//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);

此吐司的结果是“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一定存在一些大问题。

另外,假设我遇到过这个错误,那么outImagedrawnMatches究竟是什么?如果我想将潜在匹配叠加到我的640x480视频Feed上的模板(featureDetection的返回值),我会返回outImage吗?

感谢。

0 个答案:

没有答案