17

我正在编写代码以从相机预览中的可绘制对象中找到类似的对象。我正在使用最新的 Opencv 2.4.4。

以下是我的函数和 logcat 的输出。我做错了什么,我得到这样的输出?

 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();
}

日志猫:

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
4

2 回答 2

20

只是为了结束这个问题:

根据您的评论,以下行导致了问题:

dm.match(object_desc, scene_desc, matches);

我建议您手动验证:

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

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

于 2013-03-28T06:39:58.967 回答
0

(Open Cv Mat 没有类型方法)试试这个方法..

public  void match(Mat object_desc, Mat scene_desc, MatOfDMatch matches)
{
    if(object_desc.type() == scene_desc.type() &&
            object_desc.cols() == scene_desc.cols()) {            
        match_1(nativeObj, object_desc.nativeObj, scene_desc.nativeObj, matches.nativeObj);
    }

}
于 2017-06-30T06:11:01.333 回答