0
正在关注this simple example我将人脸检测功能集成到了我的照片应用中。人脸检测不起作用
我已经删除了所有形状绘制的东西,为了简单起见,我只是在寻找API来计算照片中的头数。
使用前置摄像头我拍摄照片并始终如一地无误地检测到任何脸部。
此外,在每次运行代码时(这似乎与我正在做的事情没有任何关系,但每次都会出现 - 警告是:
)在日志中存在非常可疑的警告W/ResourcesManager: Asset path '/system/framework/com.android.media.remotedisplay.jar' does not exist or contains no resources.
W/ResourcesManager: Asset path '/system/framework/com.android.location.provider.jar' does not exist or contains no resources.
这里是我的代码
照片回调
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferQualityOverSpeed = true;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
options.inPurgeable = true;
options.inInputShareable = true;
options.inMutable = true;
Bitmap temp = BitmapFactory.decodeByteArray(data, 0,
data.length, options);
countHeads(temp);
} catch (Exception e) {
Log.d(TAG, "onPictureTaken callback failed : " + e);
}
}
};
头计数器
private void countHeads(Bitmap b){
Frame frame = new Frame.Builder().setBitmap(b).build();
FaceDetector faceDetector = new FaceDetector.Builder(getApplicationContext()).setTrackingEnabled(false)
.build();
if(!faceDetector.isOperational()){
BPCAlertDialog.alert(this, "Can't build face detection");
return;
}
SparseArray<Face> faces = faceDetector.detect(frame);
//this always prints 0
Log.d(TAG, "I COUNT " + faces.size() + " FACES IN THIS PHOTO");
}
如果您知道方向,您可以在创建相框时进行设置。脸部检测器将考虑到这一点,并将检测脸部,就好像它是在一张直立的照片。请参阅此处了解更多详情:https://developers.google.com/android/reference/com/google/android/gms/vision/Frame.Builder.html#setRotation(int) – pm0733464