I am currently working on an object detection application for Android (written in Java) that uses Google ML and TensorFlow Lite. The application essentially focuses on drawing a 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 CameraX to build my camera view, and then Google ML to build the framework. The custom TF Lite model I use as a library can be found here.
Now onto the problem, HERE is what my object detection application looks like when it detects an object. As you can see, there is a heavy amount of misalignment with the boundingBox, making it appear “off”. Excuse the fact that it’s labelled as a letter opener, but this problem is persistent with any object, at any angle on the screen. It appears to be off by the same metric, always appearing just slightly above any object. My biggest concern lies with how this issue can be resolved, whether the problem is because of the TFLite model or something unrelated. The boundingBox
seems to be missing its detected object by a noticeable amount.
The following DrawGraphic.java
class is what’s responsible for drawing the boundingbox
, so here it is:
@SuppressLint(“ViewConstructor”)
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.bottom, rect.right, rect.top, borderPaint); }
}
Any additional information needed to supplement this question shall be provided upon request.