2016-12-05 14 views
1

私は、タップからフォーカス機能を備えたAndroidアプリを持っています。 Google Pixelを除いて、試したすべての端末(Nexus 5X、Samsung Galaxy S7、Asus ZenFone 3 Deluxe)でうまく動作します。Camera2 APIのフォーカスがGoogle Pixelで機能しない

public void focusAt(Point point) { 

    try { 
     // compute metering rectangle from the focus point 
     // see here: https://github.com/PkmX/lcamera/blob/master/src/pkmx/lcamera/MainActivity.scala (from line 759) 
     int meteringRectangleSize = 300; 
     int left = activeArraySize.left; 
     int right = activeArraySize.right; 
     int top = activeArraySize.top; 
     int bottom = activeArraySize.bottom; 

     float x = (float)point.x/mPreviewSize.getWidth(); 
     float y = (float)point.y/mPreviewSize.getHeight(); 

     MeteringRectangle rectangle = new MeteringRectangle(
       Math.max(0, Math.round(left + (right - left) * y - meteringRectangleSize/2)), 
       Math.max(0, Math.round(bottom - (bottom - top) * x - meteringRectangleSize/2)), 
       meteringRectangleSize, 
       meteringRectangleSize, 
       1 
     ); 

     // create a new capture request 
     mPreviewBuilder = mCameraDevice.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW); 

     // set the Auto focus mode to auto and set the region computed earlier 
     mPreviewBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO); 
     mPreviewBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_START); 
     mPreviewBuilder.set(CaptureRequest.CONTROL_AF_REGIONS, new MeteringRectangle[]{rectangle}); 

     // add the preview surface as a target and start the request 
     mPreviewBuilder.addTarget(previewSurface); 
     mPreviewSession.capture(mPreviewBuilder.build(), null, mBackgroundHandler); 

    } catch (Exception e) { 
     e.printStackTrace(); 
    } 
} 

ピクセルで何が起こっている上の任意のアイデアを:ここで

は、ユーザが画面をタップしたときに私が使用しているコードのですか?

EDI:私はactiveArraySizeこのように得た:

CameraManager manager = (CameraManager) activity.getSystemService(Context.CAMERA_SERVICE); 
String cameraId = manager.getCameraIdList()[0]; 
CameraCharacteristics characteristics = manager.getCameraCharacteristics(cameraId); 
activeArraySize = characteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE); 

答えて

1

あなたが同様にあなたのその後の繰り返しの要求にAUTOと{}の長方形にAF_REGIONSにAF_MODEを残していますか?

トリガーリクエストでAUTOに設定されている場合は、すぐにCONTINUOUS_PICTURE/no regionsまたは繰り返しリクエストが設定されている場所にオートフォーカスをリセットする可能性があります。

したがって、あなたの繰り返し要求に対してAF_MODEをAUTOに、AF_REGIONSを{rectangle}に設定してください。ただし、1回のcapture()呼び出し以上でAF_TRIGGERをSTARTに設定しないでください。

+0

お返事ありがとうございますが、私のその後の繰り返し要求はどういう意味ですか? –

+0

このコードスニペットでは、タッチ・ツー・フォーカスをトリガーする単一のキャプチャ要求を送信します。これ以外の方法でプレビューをどのように実行しますか? –

関連する問題