2013-03-27 17 views
16

Sto scrivendo il codice per trovare oggetti simili da disegnabili in camerapreview. Sto usando la nuovissima Opencv 2.4.4.Asserzioni matcher errore fallito opencv Android

Di seguito sono riportate le mie funzioni e un output da logcat. Che cosa sto sbagliando che sto ottenendo tale risultato?

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

quale linea esattamente sta fallendo su questa affermazione? Sei sicuro che 'surf.detect()' possa accettare una bitmap come input? Non dovrebbe essere un tappeto? – JonesV

+0

surf.detect() prende stuoie e oggetti e mRgba sono tappetini. La riga sottostante causa i problemi: dm.match (object_desc, scene_desc, matches); – Martus0

+3

Errore mio, non avevo visto 'Utils.bitmapToMat()'. Hai verificato manualmente che 'object_desc.type == scene_desc.type' e che' object_desc.cols == object_scene.cols'? Apparentemente c'è una sorta di incompatibilità tra il tuo 'object_desc' e' scene_desc' ... – JonesV

risposta

19

Solo per il gusto di chiudere questa domanda:

Secondo il commento, la riga seguente è stata la causa del problema:

dm.match(object_desc, scene_desc, matches); 

I consigliato di verificare manualmente che:

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

Il problema era alla fine quello per il primo frame, object_desc.cols() != scene_desc.cols(). Un semplice if è stato sufficiente per risolvere il problema.

+0

Signore, sei il mio eroe. Ci sono voluti due giorni per risolvere questo problema! +1 –

+0

Open Cv Mat non hai il metodo tipo ora ti prego di aggiornare questa risposta – Crawler

+0

hey @LiamGeorgeBetsworth .... puoi dirmi come hai risolto questo, perché sto usando il seguente approccio e l'errore è ancora lì if (thisHisto.type() == toCompareHisto.type() && thisHisto.cols() == aCompareHisto.cols()) { matcher.match (thisHisto, toCompareHisto, corrisponde); } – AwaisMajeed

0

(aperto Cv Mat doestn't avere tipo di metodo) provare questo metodo ..

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

}