rect crop (aka. digital zoom) for useCaseGroup

106 views
Skip to first unread message

Christian Günther

unread,
Oct 27, 2022, 3:20:09 PM10/27/22
to Android CameraX Discussion Group
Hi there,

i want to achieve an rectangle crop for all use-cases in my useCaseGroup. Those are preview, image-analysis and capture.

It seems exactly for that the ViewPort is meant to be used:

Nevertheless, i am not able to find how to achieve my desired behavior. I want to have an quadratic centered crop rectangle, which is 50% smaller than the smallest axis. I want this to behave like a trivial digital zoom with accordingly reduced resolution afterwards.

But creating the ViewPort i am only able to provide rationals and no specific sizes or percentages of axis. Is that even possible to achieve, what i am pointing here out?

I also came around this imageTransform output documentation:
https://developer.android.com/training/camerax/transform-output
and the setCropRect capability of an Image:

But here i am lacking an idea of how to easily integrate it with camerax and how to ensure that this is accordingly applied to all use-cases.

Is here maybe someone, having an idea on how to takle this?

best,
Christian

Xi Zhang (张熹)

unread,
Oct 27, 2022, 3:39:48 PM10/27/22
to Christian Günther, Android CameraX Discussion Group
Hi Christian,

Right now, the crop rect created by ViewPort follows the rules below:
1. must be the specified aspect ratio.
2. the sensor region must be shared by all the UseCases, 
3. follows the scale type, and 
4, maximizes the area size.

Because of 4),  unfortunately it's not possible to achieve your requirement. However you can always crop the output yourself. 
Please let me know if that works for you. Thanks,

Xi

--
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/7ab519fc-7a24-4ce3-b3ed-e3f74a656c19n%40android.com.

Christian Günther

unread,
Nov 18, 2022, 9:26:04 AM11/18/22
to Android CameraX Discussion Group, xi...@google.com, Android CameraX Discussion Group, Christian Günther
Is the https://developer.android.com/reference/androidx/camera/core/ImageProxy#setCropRect(android.graphics.Rect) setCropRect method on the imageProxy also a valid option to handle the cropping autoamtically?

Xi Zhang (张熹)

unread,
Nov 18, 2022, 12:42:15 PM11/18/22
to Christian Günther, Android CameraX Discussion Group
No. The `ImageProxy#setCropRect` only sets the value of `ImageProxy#getCropRect`. Again, the easiest path for you is getting a RGBA image and cropping it yourself. 

You mentioned that "I want this to behave like a trivial digital zoom with accordingly reduced resolution afterwards." May I ask why don't you zoom the camera instead? For example, using CameraControl#setZoomRatio

Christian Günther

unread,
Nov 21, 2022, 8:16:45 AM11/21/22
to Android CameraX Discussion Group, xi...@google.com, Android CameraX Discussion Group, Christian Günther
That is a really good question. Do you know how the resolution handling with CameraControl#setZoomRatio takes place? I need the image to be pure resolution, just cropped like old-fashioned digital zoom. An artificial resize during zooming to meet the resolutions as before would be a no-go for me. So do you know, if i get with CameraControl#setZoomRatio the reduced resolution accordingly?

Christian Günther

unread,
Nov 21, 2022, 8:21:56 AM11/21/22
to Android CameraX Discussion Group, xi...@google.com, Android CameraX Discussion Group, Christian Günther
Also it would be quite important for me to stay on the main sensor and not switch implicitly to the telephoto lens.

xi...@google.com schrieb am Freitag, 18. November 2022 um 18:42:15 UTC+1:
Reply all
Reply to author
Forward
0 new messages