更改方向时脸部无法检测到?

时间:2011-11-07 11:47:42

标签: android

我的面部检测有问题。当我将设备的方向从横向更改为纵向时,人脸检测失败。

我无法找到解决方案。这就是我试过的:

if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { 
    mCamera = Camera.open(camIdx);
    Camera.Parameters params = mCamera.getParameters();
    params.set("orientation", "portrait");
    //params.set("rotation", 90);           
    mCamera.setDisplayOrientation(90);
    //params.setRotation(90);
    //params.setPictureSize(640, 480);
    mCamera.setParameters(params);
    mCamera.startPreview();
}

每当我改变设备的方向时,我都没有检测到脸部。 请任何人帮助我,我确实尝试了所有的想法,但不能检测到脸。

2 个答案:

答案 0 :(得分:1)

我不知道您是在进行实时检测还是静止图像,但如果您尝试检测静止人像的脸部,这可能会有所帮助。以纵向模式拍摄相机中的图像,并将它们放入您在java中定义的图像视图中。 imageview应设置为比它高。现在您已经使用正确的尺寸和加载了纵向的imageView,使用以下方法将视图保存为位图:

view.setDrawingCacheEnabled(true);
Bitmap b = view.getDrawingCache();

在生成的位图上使用面部检测。这应该有效,因为faceDetection在技术上看着具有黑色背景的风景图像。 人脸检测也不适用于肖像模式,周期。

答案 1 :(得分:0)

public static void setCameraDisplayOrientation(Activity activity,
         int cameraId, android.hardware.Camera camera) {
     android.hardware.Camera.CameraInfo info =
             new android.hardware.Camera.CameraInfo();
     android.hardware.Camera.getCameraInfo(cameraId, info);
     int rotation = activity.getWindowManager().getDefaultDisplay()
             .getRotation();
     int degrees = 0;
     switch (rotation) {
         case Surface.ROTATION_0: degrees = 0; break;
         case Surface.ROTATION_90: degrees = 90; break;
         case Surface.ROTATION_180: degrees = 180; break;
         case Surface.ROTATION_270: degrees = 270; break;
     }

     int result;
     if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
         result = (info.orientation + degrees) % 360;
         result = (360 - result) % 360;  // compensate the mirror
     } else {  // back-facing
         result = (info.orientation - degrees + 360) % 360;
     }
     camera.setDisplayOrientation(result);
 }