Android 5.0 Incorrect crop areas on preview surface and captured still image

I am trying to get a digital zoom frame on Android 5.0 using camera2 interface. Related document for this developer.android.com/camera2/captureRequest feature

Surface used in my application:

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

The size of the camera sensor is 3280x2464 (4: 3 aspect ratio)

The cropping area that I want to get from the sensor:

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

I set this Rect as a parameter for the preview request:

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

And take a still image:

 stillRequestBuilder.set(CaptureRequest.SCALER_CROP_REGION, zoomCropPreview); captureSession.capture(stillRequestBuilder.build(), new captureListener() , null); 

Expected results:

  • Coz's straight rectangle is 4: 3, then the preview should be cropped vertically (mailbox)
  • The image must be accurate.
  • Both the preview and the still image should be focused on the same point in the scene and should differ only in vertical edges.

The real result:

  • Preview and still image on another scene, which seems to be moving vertically. Look at the attached images. Preview surface

Captured still image

What am I doing wrong?

+5
source share
1 answer

Fixed! The general idea is to calculate the crop area for preview and still images separately.

1) Calculate the cropping area for a still image, as in the original column (use a 4: 3 rectangle)

2) To preview, select the crop area (4: 3) and reduce the vertical size to get a 16: 9 rectangle.

+2
source

Source: https://habr.com/ru/post/1205585/


All Articles