Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

How to optimize Box coordinates on my UI?

User_LMNPLAug 29 2021

I am currently working on an object detection application for Android (written in Java) that uses Google ML. The application essentially focuses on drawing boundingBox around detected objects within a live streamed preview, provided by my device camera (via CameraX). To construct the base of this application, I used this CameraX documentation to build my camera view. Then, I used this Google ML documentation to build the framework of the application.
HERE is what my object detection application looks like when it detects an object. Excuse the fact that it's labelled as a letter opener. My biggest concern lies with how this issue can be resolved. It seems to be missing its detect object by a noticeable amount.
One thing that I think can be resolved with is if the top left left corner is moved to where the bottom left corner is. That way it can actually cover the image as a whole. How would I fix these coordinates?
Here's the DrawGraphic java file that I used to draw the boundingBox:

public class DrawGraphic extends View {

    Paint borderPaint, textPaint;
    Rect rect;
    String text;


    public DrawGraphic(Context context, Rect rect, String text) {
        super(context);
        this.rect = rect;
        this.text = text;

        borderPaint = new Paint();
        borderPaint.setColor(Color.WHITE);
        borderPaint.setStrokeWidth(10f);
        borderPaint.setStyle(Paint.Style.STROKE);

        textPaint = new Paint();
        textPaint.setColor(Color.WHITE);
        textPaint.setStrokeWidth(50f);
        textPaint.setTextSize(32f);
        textPaint.setStyle(Paint.Style.FILL);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        canvas.drawText(text, rect.centerX(), rect.centerY(), textPaint);
        canvas.drawRect(rect.left, rect.top, rect.right, rect.bottom, borderPaint);
    }
}

Comments

Processing

Post Details

Added on Aug 29 2021
0 comments
85 views