Forum Stats

  • 3,752,058 Users
  • 2,250,452 Discussions
  • 7,867,705 Comments

Discussions

How to optimize Box coordinates on my UI?

User_LMNPL
User_LMNPL Member Posts: 1 Green Ribbon

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);
    }
}