2013-04-12 169 views
12

我試圖在android上執行如下操作:http://www.youtube.com/watch?v=zjxWpKCQqJcAndroid OpenCV對象檢測

這裏我的代碼:

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

兩個工作正常! 我做錯了什麼?

回答

3

我終於完成了!

繼承人與最終結果鏈接。

Simpson Detector (OpenCV)

我希望這有助於你以某種方式,在谷歌播放,你可以看到有關該項目的更多細節和下載源代碼。隨時給我發一封電子郵件。


我以另一種方式解決了問題。 我猜Features2d.drawMatches不適用於android。可能只適用於JVM和Android中不存在的組件。如果有人能證實我很感激。

谷歌刪除了該應用程序,並沒有說明爲什麼! =( 但源代碼可與我網站上的APK一起

quintao.info


結果:https://www.youtube.com/watch?v=h2KHje-Pf10

來源:github.com/raphaelquintao/SimpsonDetector

我希望我幫助

+4

如果你自己解決了這個問題,你介意發佈什麼解決方案是?另外:您的鏈接不再工作。看起來您的應用程序在Google Play上不可用。 – pocmo

+1

我做過其他事情。我不知道爲什麼該應用從谷歌播放中刪除,但是。在我的網站上有一個鏈接到源代碼,apk包含在內。 http://quintao.info 我希望能對您有所幫助! = D –

+0

嘿,你在那裏做了很好的工作!我想問你,你是如何區分不同的辛普森人之間的區別的?我試圖做一些像你的探測器,但汽車零件。我需要區分方向盤和車輪。你能給我一些建議嗎? – definera