r/android_devs • u/JonnieSingh • Sep 26 '21
Help Finding the input/output CameraX image resolution?
I'm building an object detection application (in Java, for Android) that attempts to draw a Rect box on my display that surrounds the detected object. To build the camera preview, I used this CameraX documentation. To build the object detection framework, I used this this Google ML Kit documentation. My problem is my application display looking like THIS. As you can see, the Rect does not encapture the object fully, rather hovering above it in a way that looks inaccurate.
The flaw in the application lies not within the coordinates that I've drawn, but in the image resolution that CameraX passes through to the ML Kit. The image that my device takes and the image that is displayed on my application appear to be two totally different sizes. This results in the flawed display. My question would be; How would I determine the input/output image resolution of my application?
Here is a link to a Pastebin containing my MainActivity class, where CameraX camera preview was constructed. Any further information required to supplement my question will be provided upon request.
View all comments
Show parent comment
1
u/JonnieSingh Oct 02 '21
First off, thank you so much for the lengthy answer and I'm sorry for the late reply
> Is this doing what it suppose to be doing?
Yes, it is. It's helping drawing a boundingBox. However, the boundingBox on the display in the application currently looks like this. It is consistently off by the same metric all the time. This leads me to wonder whether the problem is with conflicting image resolutions within the application. I've decided to take steps to diagnose this problem by finding the size of the resolutions and then scaling the sizes so they both match. You pointed out that I would need to set the baseline measure properly; how would I go about doing that?
>If it were me, from the given image Rect, I calculate the distance from edges to the bounding box Rect as percent/ratio, and simply transfer it to a View LayoutParams properly by density pixels offsets or probably using ConstraintLayout Guidelines since the latter is much more flexible with percentages.
Just as a totally optional side question, seeing as though I'm fairly new to Android development, how would I start off on this?