カメラで写真を撮ることができず、顔を検出できません。画面に写真を表示すると、画像に自分の顔がはっきりと表示されますが、検出されません。私のlogcatは「顔が見つかりません!」と出力します。
public void takePictureNoPreview(Context context) {
camera = openFrontFacingCamera();
if (camera != null) {
try {
SurfaceTexture dummy = new SurfaceTexture(0);
camera.setPreviewTexture(dummy);
camera.startPreview();
camera.takePicture(null, null, this);
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
}
} else {
// booo, failed!
}
}
@Override
public void onPictureTaken(byte[] data, Camera camera) {
Log.i(LOG_TAG, "Picture taken");
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.RGB_565;
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options);
FaceDetector faceDetector = new FaceDetector(bitmap.getWidth(),
bitmap.getHeight(), 1);
Face[] faces = new Face[1];
int foundFaces = faceDetector.findFaces(bitmap, faces);
if (foundFaces > 0) {
Log.i(LOG_TAG, "Found a face!");
} else {
Log.i(LOG_TAG, "No face found!");
}
camera.release();
sendImageToActivity(bitmap);
}