好的,如果你已经安装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