Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why the result photo is zoom in than actual before take the picture❓ #2135

Closed
3 of 4 tasks
mughniaziz004 opened this issue Nov 7, 2023 · 5 comments
Closed
3 of 4 tasks
Labels
💭 question Further information is requested

Comments

@mughniaziz004
Copy link

Question

Why the result after Camera.takePhoto() is zoom in before take the picture ?

thats my code useCameraDevice and useCameraFormat
gambar

this code for create CameraUI in my app
gambar

What I tried

I tried setting the aspect ratio of camera in component Camera

VisionCamera Version

3.4.1

Additional information

@mughniaziz004 mughniaziz004 added the 💭 question Further information is requested label Nov 7, 2023
@Kieraano
Copy link

Hi,

I'm also seeing this on Android. I'm getting the issue with both Samsung and Google Pixel (both front and back cameras).

The photo that is taken is either more zoomed or less zoomed than the camera preview was at the time the photo is taken.

This is true even if the Camera preview and Result photo preview are both set to "contain". Often the resulting photo will show details that were never in the preview.

Is it taking the photo using a different format than the preview is displayed with? Or is this a configuration issue on our end?

I have read the docs.

Thanks,

@Kieraano
Copy link

Kieraano commented Nov 28, 2023

I'm still testing, but here's my current understanding of what happens:

  • When you select the format using useCameraFormat, it selects a format for you based on those requirements you're passing in. That format will contain both a photo resolution and a video resolution. The key thing to understand is that depending on the phone, there will often be formats where the aspect ratio of the photo and the aspect ratio of the video are completely different (like 0.56 vs. 0.81 for the same format!).

  • The camera preview always displays using the video aspect ratio rather than the photo aspect ratio.

  • Because of this, it can cause a complete mismatch between what you see and what you get when you take a photo.

To mitigate this, you likely want to update your code to look more like this:

const format = useCameraDevice(device, [ {photoAspectRatio: aspectRatio}, {videoAspectRatio: aspectRatio}, {photoResolution: 'max'} ]

This should prioritise fetching a format where the photo and video aspect ratios are the same, and then the camera preview should match the output photo.

I'm still learning how all of this works, so somebody please correct me if I'm wrong.

Edit: Must be something more going on. On my Google Pixel phone the output photo is still sometimes zoomed out (contains content around the sides that wasn't in the preview), even with the aspect ratios matching and everything set to contain.

This behavior is flaky - sometimes it happens sometimes it doesn't.

["Format", {"autoFocusSystem": "contrast-detection", "fieldOfView": 80.85662574623183, "maxFps": 30, "maxISO": 8982, "maxZoom": 8, "minFps": 1, "minISO": 45, "photoHeight": 1440, "photoWidth": 1920, "pixelFormats": ["yuv", "native"], "supportsDepthCapture": false, "supportsPhotoHdr": false, "supportsVideoHdr": false, "videoHeight": 1080, "videoStabilizationModes": ["off", "standard", "cinematic", "off", "cinematic-extended"], "videoWidth": 1440}]

@carlos-yoinks
Copy link

  • The camera preview always displays using the video aspect ratio rather than the photo aspect ratio.

@Kieraano You don't know how many hours I had spent trying to fix a problem with the aspect ratio and how it fit on the screen. And now, just reading The camera preview always displays using the video aspect ratio rather than the photo aspect ratio. fixed my problem on Android devices.

@Kieraano
Copy link

Kieraano commented Dec 2, 2023

  • The camera preview always displays using the video aspect ratio rather than the photo aspect ratio.

@Kieraano You don't know how many hours I had spent trying to fix a problem with the aspect ratio and how it fit on the screen. And now, just reading The camera preview always displays using the video aspect ratio rather than the photo aspect ratio. fixed my problem on Android devices.

Glad I could help. Here's the context I found for that behaviour:
#1817 (comment)

Maybe worth adding to the Readme so that other people don't get caught up by it.

@mrousavy
Copy link
Owner

Preview is in video aspect, yes. There is one bug (#2142) which I'm fixing soon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💭 question Further information is requested
Projects
None yet
Development

No branches or pull requests

4 participants