2013-03-27 61 views
16

我正在編寫代碼以在camerapreview中查找drawable中的類似對象。我正在使用最新的Opencv 2.4.4。匹配器斷言失敗錯誤opencv Android

下面是我的函數和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(); 
} 

的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 
+0

哪一行正好是在此斷言失敗?你確定'surf.detect()'可以接受一個位圖作爲輸入嗎?它不應該是一個墊子? – JonesV 2013-03-27 06:42:31

+0

surf.detect()需要墊子和物體,而mRgba是墊子。下面的代碼導致這些問題: dm.match(object_desc,scene_desc,matches); – Martus0 2013-03-27 10:40:01

+3

我的錯誤,我沒有見過'Utils.bitmapToMat()'。你是否手動驗證了'object_desc.type == scene_desc.type'和'object_desc.cols == object_scene.cols'?顯然你的'object_desc'和'scene_desc'之間有某種不兼容...... – JonesV 2013-03-27 12:41:14

回答

19

就關閉這個問題的緣故:

根據您的意見,下面一行是造成問題:

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就足以解決這個問題。

+0

你先生,我的英雄。花了兩天時間來解決這個問題! +1 – 2014-06-04 09:49:34

+0

Open Cv Mat doestn't有類型的方法現在請你更新這個答案 – Crawler 2016-06-08 07:28:00

+0

嗨@LiamGeorgeBetsworth ....你能告訴我你是如何解決這個問題的,因爲我使用了下面的方法,錯誤仍然存​​在如果(thisHisto.type()== toCompareHisto.type()&& thisHisto.cols()== toCompareHisto.cols()){ matcher.match(thisHisto,toCompareHisto,matches); } – AwaisMajeed 2017-08-23 07:30:04

0

(打開了Cv墊doestn't有類型的方法)嘗試此方法..

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

} 
相關問題