匹配断言失败错误的OpenCV的Andr​​oid [英] Matcher Assertions failed error opencv Android

查看:1185
本文介绍了匹配断言失败错误的OpenCV的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写code找到从绘制类似物体摄​​像头preVIEW。我现在用的是最新的2.4.4 opencv的

下面是我的职务,并从logcat的输出。我在做什么错了我得到这样的输出?

 公共无效detect_image(马太福音mRgba){

    object_desc =新垫();
    scene_desc =新垫();

    object_keys =新MatOfKeyPoint();
    scene_keys =新MatOfKeyPoint();

    比赛=新MatOfDMatch();
    good_matches =新MatOfDMatch();

    位图图像= BitmapFactory.de codeResource(getResources(),R.drawable.sto);
    Utils.bitmapToMat(图像对象);

    冲浪= FeatureDetector.create(FeatureDetector.FAST);
    surf.detect(对象,object_keys);
    surf.detect(mRgba,scene_keys);
    surfEX = DescriptorExtractor.create(DescriptorExtractor.BRIEF);
    surfEX.compute(对象,object_keys,object_desc);
    surfEX.compute(mRgba,scene_keys,scene_desc);
    DM = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_SL2);
    dm.match(object_desc,scene_desc,匹配);

    双max_dist = 0;
    双min_dist = 100;

    的for(int i = 0; I< object_desc.rows();我++)
      {双DIST = matches.toArray()[我] .distance;
        如果(DIST< min_dist)min_dist = DIST;
        如果(DIST> max_dist)max_dist = DIST;
      }

     的for(int i = 0; I< object_desc.rows();我++)
      {MatOfDMatch临时=新MatOfDMatch();
         如果(matches.toArray()[I] .distance 3; * min_dist)
         {temp.fromArray(matches.toArray()[I]);
             good_matches.push_back(临时);
             }
      }

}



公共垫onCameraFrame(CvCameraViewFrame inputFrame){
     mRgba = inputFrame.rgba();
             detect_image(mRgba);
     返回inputFrame.rgba();
}
 

logcat的:

 一月3号至27日:55:31.258:E / CV ::错误()(564):OpenCV的错误:断言失败
(类型== src2.type()&安培;&安培; src1.cols == src2.cols&安培;&安培;
(类型== CV_32F ||类型== CV_8U))的无效简历:: batchDistance(CV :: InputArray,
CV :: InputArray,CV :: OutputArray,INT,CV :: OutputArray,INT,INT,CV :: InputArray,
INT,BOOL),文件/home/reports/ci/slave/50-SDK/opencv/modules/core/src/stat.cpp,
行1803
 

解决方案

只是为了填补这一问题:

根据您的意见,下面一行是造成问题:

  dm.match(object_desc,scene_desc,匹配);
 

我劝你要手动验证:

 (object_desc.type == scene_desc.type和放大器;&安培;
 object_desc.cols == object_scene.cols)
 

问题是最终,对于第一帧, object_desc.cols()!= scene_desc.cols()。一个简单的如果就足以解决问题。

I'm writing code to find similar object from drawable in camerapreview. I am using the newest Opencv 2.4.4.

Below are my functions and an output from logcat. What am I doing wrong that I'm getting such output?

 public void detect_image (Mat mRgba) {

    object_desc = new Mat();
    scene_desc = new Mat();

    object_keys = new MatOfKeyPoint();
    scene_keys = new MatOfKeyPoint();

    matches = new MatOfDMatch();
    good_matches = new MatOfDMatch();

    Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.sto);
    Utils.bitmapToMat(image,object);   

    surf = FeatureDetector.create(FeatureDetector.FAST);
    surf.detect( object, object_keys );   
    surf.detect( mRgba, scene_keys);
    surfEX = DescriptorExtractor.create(DescriptorExtractor.BRIEF);
    surfEX.compute(object, object_keys, object_desc);       
    surfEX.compute(mRgba, scene_keys, scene_desc);
    dm = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_SL2);    
    dm.match(object_desc, scene_desc, matches);

    double max_dist = 0;
    double min_dist = 100;

    for( int i = 0; i < object_desc.rows(); i++ )
      { double dist = matches.toArray()[i].distance;
        if( dist < min_dist ) min_dist = dist;
        if( dist > max_dist ) max_dist = dist;
      }

     for( int i = 0; i < object_desc.rows(); i++ )
      {  MatOfDMatch temp = new MatOfDMatch();
         if( matches.toArray()[i].distance < 3*min_dist )
         {   temp.fromArray(matches.toArray()[i]);
             good_matches.push_back(temp); 
             }        
      }

}



public Mat onCameraFrame(CvCameraViewFrame inputFrame) {        
     mRgba = inputFrame.rgba();
             detect_image(mRgba);
     return inputFrame.rgba();
}

Logcat:

03-27 01:55:31.258: E/cv::error()(564): 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 1803

解决方案

Just for the sake of closing this question:

According to your comment, the following line was causing the problem:

dm.match(object_desc, scene_desc, matches);

I advised you to manually verify that:

(object_desc.type == scene_desc.type &&
 object_desc.cols == object_scene.cols)

The problem was eventually that for the first frame, object_desc.cols() != scene_desc.cols(). A simple if was enough to solve the problem.

这篇关于匹配断言失败错误的OpenCV的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆