2012-07-02 40 views
0

我正在使用Android二進制文件,這是我第一次在OpenCV中執行距離轉換。 OpenCV specification表示distanceTransform的輸出圖像是一個32位浮點單通道圖像。我把它變成了一個mat(mDist),但是在創建一個位圖時拋出了一個IllegalStateException異常。這是由於輸出和墊子對象的不兼容嗎?我是否必須指定墊子的顏色通道細節?以下是我的代碼部分。OpenCV輸出錯誤的距離變換

enter image description here

 Mat mImg = new Mat(); 
     Mat mThresh = new Mat(); 
     Mat mDist = new Mat(); 

     ImageView imgView = (ImageView) findViewById(R.id.imageView); 
     Bitmap bmpIn = BitmapFactory.decodeResource(getResources(), 
       R.drawable.w1);  
     Utils.bitmapToMat(bmpIn, mImg); //Load image to mat 

     Imgproc.cvtColor(mImg, mImg, Imgproc.COLOR_BGR2GRAY);  
     Imgproc.threshold(mImg, mThresh, 0, 255, Imgproc.THRESH_BINARY 
       | Imgproc.THRESH_OTSU); //Grayscale and thresholding   

     Imgproc.distanceTransform(mThresh, mDist, Imgproc.CV_DIST_L2, Imgproc.CV_DIST_MASK_PRECISE); 

     Bitmap bmpOut = Bitmap.createBitmap(mDist.cols(), mDist.rows(), 
       Bitmap.Config.ARGB_8888); 

     Utils.matToBitmap(mDist, bmpOut); //Error in creating bitmap 
     imgView.setImageBitmap(bmpOut); 

回答

0

故障是在下面的行的代碼;

Bitmap bmpOut = Bitmap.createBitmap(mDist.cols(), mDist.rows(), 
       Bitmap.Config.ARGB_8888); 

應該應用的Bitmap.Config不是ARGB_8888。該功能創建一個8位單通道墊。