2011-11-07 28 views
2

我有面部檢測問題。當我將設備的方向從橫向更改爲縱向時,臉部檢測失敗。更改方向時不會檢測到臉部?

我無法找到解決方案。這是我試過的:

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(); 
} 

每當我改變我的設備的方向,我沒有得到面部檢測。 請有人幫助我,我做了所有認爲但不能檢測臉。

回答

1

我不知道您是否正在進行實時檢測或靜止圖像,但如果您嘗試檢測靜物肖像的臉部,這可能會有所幫助。以肖像模式拍攝相機中的圖像,並將它們放入您在java中定義的圖像視圖中。 imageview應該設置得比它高。現在,你有正確的尺寸,並裝上其肖像的ImageView的,保存使用該視圖作爲位圖:在生成位圖

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

使用人臉檢測。這應該是有效的,因爲faceDetection技術上是在查看黑色背景的風景圖像。 人臉檢測也不適用於肖像模式,期間。

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); 
} 
+4

如果你能解釋你的代碼是什麼以及它如何回答問題,可能會更有幫助。 – DaveHogan