[英]Android face detection MaxNumDetectedFaces
所以我只是將我的平板電腦(原始華碩變換器)升級到Android版本4.0.3,以使用面部檢測構建應用程序。 但每次我啟動它並嘗試開始面部檢測我在logcat中得到這個錯誤:
E/AndroidRuntime(1755): java.lang.IllegalArgumentException: invalid face detection type=0
我在文件中讀到它意味着可以檢測到或支持0個面,但這是否意味着我的設備根本無法檢測到面部或者是否可以改變它? 它還使用后置攝像頭,將它更改為其他攝像頭改變什么? 我一直試圖這樣做,但我無法弄清楚如何,我試圖運行的項目可以在這里找到:
https://docs.google.com/open?id=0B2Nu5U2Cz81qZExGQ25sWVdRd21IOExUUTZsZzFoZw
從這個SO問題: Android臉部探測器使用Android相機
請記住,您可以使用舊的FaceDetector API檢測面部。 它已經從API級別1開始存在,並且應該適用於所有帶攝像頭的手機。 當檢測到面部時,它還會返回一個邊界框。
public Rect findFace(Bitmap bmp) {
// Ask for 1 face
Face faces[] = new FaceDetector.Face[1];
FaceDetector detector = new FaceDetector( bmp.getWidth(), bmp.getHeight(), 1 );
int count = detector.findFaces( bmp, faces );
Face face = null;
if( count > 0 ) {
face = faces[0];
PointF midEyes = new PointF();
face.getMidPoint( midEyes );
Log.i( TAG,
"Found face. Confidence: " + face.confidence() + ". Eye Distance: " + face.eyesDistance() + " Pose: ("
+ face.pose( FaceDetector.Face.EULER_X ) + "," + face.pose( FaceDetector.Face.EULER_Y ) + ","
+ face.pose( FaceDetector.Face.EULER_Z ) + "). Eye Midpoint: (" + midEyes.x + "," + midEyes.y + ")" );
float eyedist = face.eyesDistance();
PointF lt = new PointF( midEyes.x - eyedist * 2.0f, midEyes.y - eyedist * 2.5f );
// Create rectangle around face. Create a box based on the eyes and add some padding.
// The ratio of head height to width is generally 9/5 but that makes the rect a bit to tall.
return new Rect(
Math.max( (int) ( lt.x ), 0 ),
Math.max( (int) ( lt.y ), 0 ),
Math.min( (int) ( lt.x + eyedist * 4.0f ), bmp.getWidth() ),
Math.min( (int) ( lt.y + eyedist * 5.5f ), bmp.getHeight() )
);
}
return null;
}
對於像我這樣的人,
請參閱鏈接中的代碼,並檢查可能的異常(例如,非法的參數異常可以通過不同的輸入位圖大小拋出,其初始大小為FaceDetection對象,第138行〜)
您應首先調用getMaxNumDetectedFaces()以查看您的設備是否支持它。 如果支持,返回值應> 0。 就像我在上一個問題中提到的那樣,設備相機模塊和驅動程序也必須支持它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.