我有這樣的問題,當我試圖找到眼睛與OpenCV庫爲Android眼鏡我的代碼不能正常工作。
我的代碼如下:查找眼睛配眼鏡的OpenCV
try {
InputStream is = this.getResources().openRawResource(R.raw.haarcascade_eye_tree_eyeglasses);
File cascadeDir = this.getDir("cascade"+"occhiOcchiali", Context.MODE_PRIVATE);
File cascadeFile = new File(cascadeDir, "haarcascade_eye_tree_eyeglasses.xml");
FileOutputStream os = new FileOutputStream(cascadeFile);
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = is.read(buffer)) != -1) {
os.write(buffer, 0, bytesRead);
}
is.close();
os.close();
mioClassificatoreOcchiOcchiali = new CascadeClassifier(cascadeFile.getAbsolutePath());
Log.d("metodo1", cascadeFile.getAbsolutePath());
if (mioClassificatoreOcchiOcchiali.empty()) {
Log.d("metodo1", "Failed to load cascade classifier");
mioClassificatoreOcchiOcchiali = null;
} else
Log.d("metodo1", "Loaded cascade classifier from " + cascadeFile.getAbsolutePath());
cascadeFile.delete();
cascadeDir.delete();
} catch (IOException e) {
e.printStackTrace();
Log.d("metodo1" , "Failed to load cascade. Exception thrown: " + e);
}
這樣,我把我的分類,並使用此代碼我試圖找到眼睛配眼鏡:
LinkedList<org.opencv.core.Rect> occhi = new LinkedList<org.opencv.core.Rect>();
org.opencv.core.Size sOcchi = new org.opencv.core.Size(15, 15);
mioClassificatoreOcchiOcchiali.detectMultiScale(matOcchi, occhi,1.1, 2,0,sOcchi);
結果總是0 insted的,如果我離開我的眼鏡,結果總是2.
任何人都可以幫助我?
在此先感謝。
做爲Haar分類對眼睛不戴眼鏡代碼的工作? – sarwar 2012-02-23 16:07:05
是的,它沒有眼鏡就能很好地工作。爲什麼?你可以幫助我? – 2012-02-23 16:08:53