對於初學者問題,我很抱歉,但我還沒有找到答案。 我試圖實時檢測臉部和眼睛。如果我僅使用人臉檢測或僅使用眼睛檢測,則代碼(在android openCV上運行)工作良好,但是當我將兩者結合使用時(如附加的代碼中),程序在運行時崩潰。我不知道如何結合這兩個級聯(一個在臉部周圍顯示矩形,另一個在眼睛周圍)。任何幫助將不勝感激!使用兩個cacscade分類器進行臉部和眼睛檢測
InputStream is3 = context.getResources().openRawResource(R.raw.lbpcascade_frontalface);
File cascadeDir = context.getDir("cascade", Context.MODE_PRIVATE);
File cascadeFile = new File(cascadeDir, "lbpcascade_frontalface.xml");
File cascadeFileEye = new File(cascadeDir, "eyes_detect.xml");
FileOutputStream os = new FileOutputStream(cascadeFile);
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = is3.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
}
is3.close();
os.close();
FileOutputStream os1 = new FileOutputStream(cascadeFileEye);
byte[] bufferEye = new byte[4096];
int bytesReadEye;
while ((bytesReadEye = is3.read(bufferEye)) != -1) {
os1.write(bufferEye, 0, bytesReadEye);
}
is4.close();
os1.close();
mCascade = new CascadeClassifier(cascadeFile.getAbsolutePath());
mCascadeEye = new CascadeClassifier(cascadeFileEye.getAbsolutePath());
if (mCascade.empty()) {
//Log.e(TAG, "Failed to load cascade classifier");
mCascade = null;
}
if (mCascadeEye.empty()) {
//Log.e(TAG, "Failed to load cascade classifier");
mCascadeEye = null;
}
cascadeFile.delete();
cascadeDir.delete();