Android 5.0 Wrong crop regions on preview surface and captured still image

霸气de小男生 提交于 2019-12-18 08:33:34

问题


I'm trying to get digital zoomed frame on Android 5.0 with camera2 interface. Appropriate doc for that functionality is developer.android.com/camera2/captureRequest

Surface used in my application:

  • SurafaceView (1920x1080, 16:9 aspect ratio)
  • ImageReader (3264x2448, 4:3 aspect ratio)

Camera's sensor size is 3280x2464 (4:3 aspect ratio)

Crop region which I want to get from sensor is:

Rect zoomCropPreview = new Rect(1094, 822, 2186, 1642); //(1092x820, 4:3 aspect ratio)

I set this Rect as parameter for preview request:

previewRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, zoomCropPreview);
captureSession.setRepeatingRequest(previewRequestBuilder.build(), null, null);

And to take still image:

stillRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, zoomCropPreview);

captureSession.capture(stillRequestBuilder.build(), new captureListener() , null);

Expected results:

  • Coz crop rectangle is 4:3 ratio, then preview should be cropped vertically (letterbox)
  • Still image should be exact crop region.
  • Both preview and still image should be centered on the same point of scene, and should differ only in vertical edges.

Real result:

  • Preview and still image point on different scene which seems to be moved vertically. Look at attach images.

What am I doing wrong?


回答1:


Fixed! General idea is to calculate crop region for preview and still images separately.

1) Calculate crop region for still image as in initial post (use 4:3 rectangle)

2) For preview take above crop region (4:3) and reduce vertical size to get 16:9 rectangle.



来源:https://stackoverflow.com/questions/26583489/android-5-0-wrong-crop-regions-on-preview-surface-and-captured-still-image

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!