Apparence-io / CamerAwesome

📸 Embedding a camera experience within your own app shouldn't be that hard. A flutter plugin to integrate awesome Android / iOS camera experience.
https://ApparenceKit.dev
MIT License
911 stars 200 forks source link

Better control over camera resolution #217

Open apalala-dev opened 1 year ago

apalala-dev commented 1 year ago

Proposal

With the release of CamerAwesome 1.0.0, we lost the ability to know and choose the resolution we want to take pictures with.

Instead, we can set an aspect ratio that is respected both on the preview and on the image captured with the best resolution available. Some use cases need to set a lower resolution and to know what resolution it will be.

Android side

We are now using CameraX instead of Camera2, which comes with its pros and cons. When asking to take a picture, we can set either a target aspect ratio OR a target resolution. The targeted aspect ratio should be respected but the target resolution can vary for several reasons:

Having a different aspect ratio than the preview seems wrong. One solution is to scale/crop the picture taken to better match the preview but it won't have the exact same resolution as we've set in target resolution.

Additionally, getting the list of camera resolutions is not as easy as it seems since the camera used can vary depending on settings such as the zoom ratio. On a Pixel 7 Pro for instance, there are several lenses with different zoom levels and with different resolutions available. Depending on the current zoom, CameraX will take the picture with one or the other lens resulting in a varying resolution.

Here is the list of possibilities we have in mind

1. Only let users set aspect ratio (current solution)

When setting an aspect ratio, target resolution is the best possible available. It's up to the user to resize it afterwards if they need it at a lower resolution.

2. Let users set target resolution OR target aspect ratio

Similar to CameraX, the user could set either a target resolution OR an aspect ratio but not both at the same time.

When setting a target resolution, images taken might have a different resolution than the target resolution, but should be close. Aspect ratio might not be the same.

When setting an aspect ratio, target resolution would be the best possible available (like now). It's up to the user to resize it afterwards if they need it at a lower resolution.

3. Set target resolution AND aspect ratio

Let the user set a target resolution and a target aspect ratio.

a. Aspect ratio priority

Set only the target aspect ratio to CameraX to ensure we get the same aspect ratio. Resize the image captured to match the target resolution.

b. Target resolution priority

Set only the target resolution to CameraX to ensure we get a close resolution. Scale / crop the image captured to match the target aspect ratio.

Other possible improvement

iOS side

To be completed.

EggsAreUs commented 1 year ago

Hi Team, Thank you for a great plugin. Understand about the aspect ratio/resolution dilemma but having a photo that has a degree of resolution control would be of a great benefit (to us).

Our app is looking to allow the user to take several photos manually in succession, with the camera remaining open, producing low-medium resolution images (as they need to uploaded and stored on a server with a reasonable limit on storage for each user). Resizing large resolution images (possibly about 16x the required final size or more with no compression) is quite slow and does interfere with capturing the photos.

From our perspective, it would be useful to set/limit resolution in one dimension bringing it approximately into the ball-park of desired file-size. Agreed that aspect ratio shouldn't actually crop part of the preview but if it makes the final image wider in one dimension, it's not too much of an issue, generally (I think), as it could be cropped later. (Perhaps the preview could be partly cropped in the narrower side for a degree of safety?). Cropping a slightly larger image would take a fraction of the time of cropping a very large one.

Hope that I haven't missed the point entirely.

rubenferreira97 commented 1 year ago

@apalala-dev CameraX 1.3.0-alpha06 was released on April 19, 2023 and defines a new API ResolutionSelector which allows to specify aspect ratio and resolution strategies with fallback rules or a custom resolution filter to get the desired results on Android. Maybe use this new API to solve this issue?


Not related to this issue but 1.3.0-alpha06 also brings a new feature called Concurrent Camera which supports simultaneous streaming of camera devices (allows a device to have both the front and back cameras operating at the same time). CamerAwesome already has a beta multi camera support in iOS with https://github.com/Apparence-io/CamerAwesome/pull/303 and on Android with https://github.com/Apparence-io/CamerAwesome/commit/c6940743ce5aa961491b0c7ae4c7c4b39c65d4fe. Does https://github.com/Apparence-io/CamerAwesome/commit/c6940743ce5aa961491b0c7ae4c7c4b39c65d4fe uses this API?

apalala-dev commented 1 year ago

@apalala-dev CameraX 1.3.0-alpha06 was released on April 19, 2023 and defines a new API ResolutionSelector which allows to specify aspect ratio and resolution strategies with fallback rules or a custom resolution filter to get the desired results on Android. Maybe use this new API to solve this issue?

I saw they added this along with other interesting features. There are several things to stabilize first but that's definitively something I'd like to explore, given the opportunity. It should come after the 2.0 release.


Not related to this issue but 1.3.0-alpha06 also brings a new feature called Concurrent Camera which supports simultaneous streaming of camera devices (allows a device to have both the front and back cameras operating at the same time). CamerAwesome already has a beta multi camera support in iOS with #303 and on Android with c694074. Does c694074 uses this API?

That's what we're using for Android 👍 It's still in beta but feel free to share any feedback on the feature :) If you try it and find a bug, don't forget to specify on which platform. 🙏