2014-11-21 23 views
0

我試圖顯示一個圖像與檢測到的關鍵點。在我的代碼中,我得到了關鍵點的列表,我的屏幕上無法顯示圖像。我認爲我的問題是將圖像轉換爲來自MAT的位圖。 我做錯了什麼?在Android上顯示圖像的關鍵點 - OpenCV

這裏是我的代碼:

Mat teste = new Mat(); 
    Mat mRgba = teste.clone(); 
    Mat outputMat = new Mat(); 

    BitmapDrawable drawable = (BitmapDrawable) imageView.getDrawable(); 
    Bitmap bitmap = drawable.getBitmap(); 
    Utils.bitmapToMat(bitmap, teste); 

    MatOfKeyPoint myKeyPoints = new MatOfKeyPoint(); 
    FeatureDetector orb = FeatureDetector.create(FeatureDetector.ORB); 
    orb.detect(teste, myKeyPoints); 

    List<KeyPoint> referenceKeypointsList = 
      myKeyPoints.toList(); 


    Imgproc.cvtColor(teste, mRgba, Imgproc.COLOR_RGBA2RGB,4); 
    Features2d.drawKeypoints(mRgba, myKeyPoints, mRgba, new Scalar(2,254,255), Features2d.DRAW_RICH_KEYPOINTS); 
    Imgproc.cvtColor(mRgba, outputMat, Imgproc.COLOR_RGB2RGBA); 
    Utils.matToBitmap(outputMat, bitmap); 

    imageView.setImageBitmap(bitmap); 
+0

BTW引用:mRgba應該叫mRgb因爲根據您的使用cvtColor它不包含alpha通道。我不確定Imgproc.COLOR_RGBA2RGB,4導致什麼 - 可能刪除4,因爲你想要一個RGB圖像,即三個通道 – PhilLab 2014-11-22 15:35:28

+0

4它就像Features2d.DRAW_RICH_KEYPOINTS。 – NatsuDragonEye 2014-11-22 16:19:53

+0

變量的名稱是一個錯誤。我的結果就像一個白色的屏幕,就是它。我不明白爲什麼,我喜歡這種方式:[按照鏈接](http://stackoverflow.com/questions/20537280/keypoint-list-to-matofkeypoint?rq=1) – NatsuDragonEye 2014-11-22 16:21:00

回答

1

看我的代碼。它工作正常

int whichDescriptor = siftDescriptor; //freakDescriptor; 

     // Features SEARCH 
     int detectorType = FeatureDetector.SIFT; 
     FeatureDetector detector = FeatureDetector.create(detectorType); 

     Mat mask = new Mat(); 
     MatOfKeyPoint keypoints = new MatOfKeyPoint(); 
     detector.detect(image, keypoints , mask);    

     if (!detector.empty()){ 

      // Draw kewpoints 
      Mat outputImage = new Mat(); 
      Scalar color = new Scalar(0, 0, 255); // BGR 
      int flags = Features2d.DRAW_RICH_KEYPOINTS; // For each keypoint, the circle around keypoint with keypoint size and orientation will be drawn. 
      Features2d.drawKeypoints(image, keypoints, outputImage, color , flags); 
      displayImage(Mat2BufferedImage(outputImage), "Feautures_"+detectorType); 
     } 

displayImage()和Mat2BufferedImage()在這裏 link1link2

+0

它的作品:)非常感謝:D – NatsuDragonEye 2014-11-27 13:48:30