2015-11-01 34 views
0

我想在android中的多個模板匹配。我寫了一段代碼,但在此代碼中,當我嘗試使用「Utils」轉換matToBitmap時。它說Utils不能重新解決。我添加了JRE系統庫。導入很多包,但沒有解決這個問題。這裏是我的代碼:Utils無法解析在Android Opencv

package com.example.tryapp; 
import org.opencv.core.Core; 
import org.opencv.core.CvType; 
import org.opencv.core.Mat; 
import org.opencv.core.Point; 
import org.opencv.core.Scalar; 
import org.opencv.core.Core.MinMaxLocResult; 
import org.opencv.imgcodecs.Imgcodecs; 
import org.opencv.imgproc.Imgproc; 
import android.app.Activity; 
import android.graphics.Bitmap; 
import android.support.v7.app.ActionBarActivity; 
import android.widget.ImageView; 

[I imported all of this package one by one but none of this work][1] 


public class tmpmatch extends Activity{ 

static void match() 
{ 

int match_method=Imgproc.TM_CCOEFF; 
String img ="res/drawable/lena.png"; 
String tm1img ="res/drawable/those_eyes.png"; 
String tm2img ="res/drawable/eye2.png"; 
String outFile="res/drawable/tmp.png"; 
Mat mimg=Imgcodecs.imread(img); 
Mat mtm1img=Imgcodecs.imread(tm1img); 
Mat mtm2img=Imgcodecs.imread(tm2img); 
int result_cols = mimg.cols() - mtm1img.cols() + 1; 
int result_rows = mimg.rows() - mtm1img.rows() + 1; 
int result_cols2 = mimg.cols() - mtm2img.cols() + 1; 
int result_rows2 = mimg.rows() - mtm2img.rows() + 1; 
Mat result = new Mat(result_rows, result_cols, CvType.CV_32FC1); 
Mat result2 = new Mat(result_rows2, result_cols2, CvType.CV_32FC1); 

Imgproc.matchTemplate(mimg, mtm1img, result,Imgproc.TM_CCOEFF); 
Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat()); 
Imgproc.matchTemplate(mimg, mtm2img, result2, Imgproc.TM_CCOEFF); 
Core.normalize(result2, result2, 0, 1, Core.NORM_MINMAX, -1, new Mat()); 

MinMaxLocResult mmr = Core.minMaxLoc(result); 
MinMaxLocResult mmr2 = Core.minMaxLoc(result2); 

Point matchLoc,matchLoc2; 
if (match_method == Imgproc.TM_SQDIFF || match_method == Imgproc.TM_SQDIFF_NORMED) { 
    matchLoc = mmr.minLoc; 
    matchLoc2 = mmr2.minLoc; 
} else { 
    matchLoc = mmr.maxLoc; 
    matchLoc2 = mmr2.maxLoc; 
} 

///Show me what you got 
Imgproc.rectangle(mimg, matchLoc, new Point(matchLoc.x + mtm1img.cols(), 
     matchLoc.y + mtm1img.rows()), new Scalar(0, 255, 0)); 
Imgproc.rectangle(mimg, matchLoc2, new Point(matchLoc2.x + mtm2img.cols(), 
     matchLoc2.y + mtm2img.rows()), new Scalar(0, 255, 0)); 


// Save the visualized detection. 
//System.out.println("Writing "+ outFile); 
//Imgcodecs.imwrite(outFile, mimg); 
//System.out.println("written"); 

Mat android_image = Mat.zeros(mimg.cols(), mimg.rows(), CvType.CV_8UC1); 

Imgproc.cvtColor(mimg, android_image, Imgproc.COLOR_BGR2RGB); 

Bitmap bm = Bitmap.createBitmap(android_image.cols(),android_image.rows(), Bitmap.Config.ARGB_8888); 

Utils.matToBitmap(android_image, bm); 

ImageView iv = (ImageView) findViewById(R.id.image); 
iv.setImageBitmap(bm); 


} 
public static void main(String[] args) { 
     System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 
     match(); 

} 

}

+0

請幫我看看我卡在這裏。我正在使用opencv 3.00 – user2215160

回答