CameraX captured image size and PreviewView size are not the same for some device

989 views
Skip to first unread message

Mohammad Sajib Al Seraj

unread,
Sep 27, 2022, 12:39:25 PM9/27/22
to Android CameraX Discussion Group

I am trying to use CameraX for image capture and capture preview. I found captured image and preview image different for google pixel 5a, but for Samsung A72 device captured image and preview image are same. For pixel phone, the captured image is left aligned. For both Image analysis and PreviewView, I've set setTargetAspectRatio(AspectRatio.RATIO_4_3). I have also tried to use ViewPort API to fix this issue. Any help will be appreciated.

Code snipped is attached here.

@SuppressLint({"RestrictedApi", "WrongConstant", "UnsafeOptInUsageError"})
private void startCameraX(ProcessCameraProvider cameraProvider) throws ExecutionException, InterruptedException {
    Preview preview =
new Preview.Builder()
            .setTargetAspectRatio(AspectRatio.
RATIO_4_3)
            .build()
;
   
preview.setSurfaceProvider(previewView.getSurfaceProvider());

   
CameraSelector cameraSelector;
   
cameraSelector = new CameraSelector.Builder()
            .requireLensFacing(
LENS_FACING)
            .build()
;

   
// Image capture use case
   
imageCapture = new ImageCapture.Builder()
            .setJpegQuality(
100)
            .setTargetAspectRatio(AspectRatio.
RATIO_4_3)
            .setCameraSelector(cameraSelector)
            .build()
;

   
Rational aspectRatio = new Rational(previewView.getWidth(), previewView.getHeight());
   
ViewPort viewPort = new ViewPort.Builder(aspectRatio, preview.getTargetRotation()).setScaleType(ViewPort.FIT).build();

   
UseCaseGroup useCaseGroup = new UseCaseGroup.Builder()
            .setViewPort(viewPort)
            .addUseCase(preview)
            .addUseCase(
imageCapture)
            .build()
;

   
camera = cameraProvider.bindToLifecycle(this, cameraSelector,useCaseGroup);

   
// For performing operations that affect all outputs.
   
CameraControl cameraControl = camera.getCameraControl();

   
cameraControl.setLinearZoom(zoom);
   
setCaptureRequestOptionsISOandShutterSpeed();
}

 

<androidx.camera.view.PreviewView
   
android:id="@+id/camera_preview"
   
android:layout_width="0dp"
   
android:layout_height="match_parent"
   
android:layout_weight="1" />

Xi Zhang (张熹)

unread,
Sep 27, 2022, 1:36:42 PM9/27/22
to Mohammad Sajib Al Seraj, Android CameraX Discussion Group
Could you share the misaligned results from preview v.s. ImageCapture? For preview you can get a snapshot using PreviewView#getBitmap().

--
You received this message because you are subscribed to the Google Groups "Android CameraX Discussion Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to camerax-develop...@android.com.
To view this discussion on the web visit https://groups.google.com/a/android.com/d/msgid/camerax-developers/CAHDOb3mU-uXeqTgsqz7KKxzS%3DxFo9vrF5kyjic9%2Bjbq5CSmnAw%40mail.gmail.com.

Mohammad Sajib Al Seraj

unread,
Sep 27, 2022, 2:42:04 PM9/27/22
to Xi Zhang (张熹), Android CameraX Discussion Group
I have attached preview image and captured image here.

Thanks
Mohammad
Preview image.png
Capture image.jpg

Xi Zhang (张熹)

unread,
Sep 27, 2022, 3:20:16 PM9/27/22
to Mohammad Sajib Al Seraj, Android CameraX Discussion Group
Could you try and see if you can repro the issue with this APK? This is a CameraX test app. 

Xi Zhang (张熹)

unread,
Sep 27, 2022, 5:35:00 PM9/27/22
to Mohammad Sajib Al Seraj, Android CameraX Discussion Group
Thanks for confirming it. If I were to take a guess, it's probably the PreviewView gets clipped by the UI.

The test app is hosted on GitHub:  https://github.com/androidx/androidx/tree/androidx-main/camera/integration-tests/viewtestapp/src/main/java/androidx/camera/integration/view 

On Tue, Sep 27, 2022 at 2:01 PM Mohammad Sajib Al Seraj <mals...@mtu.edu> wrote:
The test app is behaving as expected.

On Tue, Sep 27, 2022 at 3:56 PM Mohammad Sajib Al Seraj <mals...@mtu.edu> wrote:
Can you please share the source code link of the test app?

Thanks
Mohammad

On Tue, Sep 27, 2022 at 3:55 PM Mohammad Sajib Al Seraj <mals...@mtu.edu> wrote:
The test behaved normally. I am using relative layout. Do you think it might create an issue?

Thanks
Mohammad

On Tue, Sep 27, 2022 at 3:42 PM Mohammad Sajib Al Seraj <mals...@mtu.edu> wrote:
Thanks, I'll check it out. 

On Tue, Sep 27, 2022 at 3:36 PM Xi Zhang (张熹) <xi...@google.com> wrote:
Sorry, that's the internal link. This public link should work:

https://issuetracker.google.com/action/issues/247964494/attachments/39078078?download=true

On Tue, Sep 27, 2022 at 12:27 PM Mohammad Sajib Al Seraj <mals...@mtu.edu> wrote:
It is asking for SSO username and password. Do I have to create SSO account?

Thanks
Mohammad

Mohammad Sajib Al Seraj

unread,
Sep 27, 2022, 5:38:50 PM9/27/22
to Xi Zhang (张熹), Android CameraX Discussion Group
Thank you so much. I will check it.
Reply all
Reply to author
Forward
0 new messages