14

我试图实现这样的事情:http ://www.youtube.com/watch?v=zjxWpKCQqJc on android。

这是我的代码:

public Mat onCameraFrame(CvCameraViewFrame inputFrame) {
    Mat novo = new Mat();
    Mat resp = new Mat();
    Mat homer = new Mat();

    //resp = inputFrame.gray();
    novo = inputFrame.gray();

    Mat lido = new Mat();
    try {
        lido = Utils.loadResource(this, R.drawable.homer);
    } catch (IOException e) {
        e.printStackTrace();
    }
    Imgproc.cvtColor(lido, homer, Imgproc.COLOR_RGB2GRAY);

    FeatureDetector surf = FeatureDetector.create(FeatureDetector.FAST);

    MatOfKeyPoint keypointsHomer = new MatOfKeyPoint();
    MatOfKeyPoint keypoints = new MatOfKeyPoint();

    surf.detect(homer, keypointsHomer);
    surf.detect(novo, keypoints);

    DescriptorExtractor SurfExtractor = DescriptorExtractor.create(FeatureDetector.SURF);

    Mat descriptors = new Mat();
    Mat homerDescriptors = new Mat();

    SurfExtractor.compute(novo, keypoints, descriptors);
    SurfExtractor.compute(homer, keypointsHomer, homerDescriptors);

    DescriptorMatcher m = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);
    MatOfDMatch matches = new MatOfDMatch();

    m.match(descriptors, homerDescriptors, matches);

    Features2d.drawMatches(novo, keypoints, homer, keypointsHomer, matches, resp);

    return resp;
}

我收到以下错误:https ://dl.dropboxusercontent.com/u/2345114/error_android.png

如果我尝试像这样绘制关键点:

Features2d.drawKeypoints(novo, keypoints, resp);
Features2d.drawKeypoints(homer, keypointsHomer, resp);

两者都工作正常!我做错了什么?

4

0 回答 0