好的,如果你已經安裝OpenCV for Android,你可以使用Java類和方法來達到你的目的;如果你真的想要使用C++對象,你必須去開發NDK ...
但在你的情況下,確實沒有Java的OpenDSP for Android CvHaardetectobjects
;但在這種情況下,您可以將HaarCascade加載到CascadeClassifier
之後,然後您可以使用detectMultiScale
執行基於HaarCascade的檢測。
而你得到的結果與CvHaardetectobjects
相同。
請參見下面的代碼:
爲Android
/////////////Load the HaarCascade file into the clsssifier
try {
InputStream is3 = getResources().openRawResource(R.raw.haarcascade_mcs_mouth);
File cascadeDir = getDir("cascade", Context.MODE_PRIVATE);
File mCascadeFile = new File(cascadeDir, "haarcascade_mcs_mouth.xml");
FileOutputStream os3 = new FileOutputStream(mCascadeFile);
byte[] buffer = new byte[4096];
int bytesRead;
Log.e("","Non c'è problema PRIMA della lettura del file");
while ((bytesRead = is3.read(buffer)) != -1) {
os3.write(buffer, 0, bytesRead);
}
is3.close();
os3.close();
Log.e("","Non c'è problema con la lettura del file");
mJavaDetector = new CascadeClassifier(mCascadeFile.getAbsolutePath());
if (mJavaDetector.empty()) {
Log.e(TAG, "Failed to load cascade classifier");
mJavaDetector = null;
} else
Log.e(TAG, "Loaded cascade classifier from " + mCascadeFile.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
Log.e(TAG, "Failed to load cascade. Exception thrown: " + e);
}
//////Call detectMultiScale with the Detector that contains the cascade
mJavaDetector.detectMultiScale(mat,MapofRect,1.15,4,0,new Size(25,15),new Size(face.width(),face.height()/2));
@ 2vision2如果答案有用,請記得通過檢查左側的綠色檢查來接受它。如果不是,請詢問更多。 – 2013-02-16 11:12:59