1

カメラで写真を撮ることができず、顔を検出できません。画面に写真を表示すると、画像に自分の顔がはっきりと表示されますが、検出されません。私の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);
}
4

1 に答える 1

0

解決策は、カメラの画像を 90 度回転させることでした。カメラから返された画像は 90 度ずれていたため、FaceDetector は画像を適切に処理できませんでした。

Matrix matrix = new Matrix();
matrix.postRotate(90);
bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
于 2012-12-28T21:03:02.740 に答える