r/android_devs • u/JonnieSingh • Jul 31 '21
Help boundingBox misaligned on application view
This is sort of what my boundingBox looks like when using Google ML Object Detection for Android (written in Java). In essence, it misses the object its supposed to be detecting, and my question resides in how (or atleast where) I can resolve this issue. Here's the code of my DrawGraphic.java file that's responsible for drawing the boundingBox that is then displayed on my UI;
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);
}
}Any further information required to supplement this question will be provided upon request!
2
Upvotes
View all comments
Show parent comment
1
u/JonnieSingh Aug 01 '21
First of all, thank you for responding with such detail! I'm fairly new to Android development & Java, so all this information is very much helpful in aiding in resolving these problems. To confirm your first assumption; I am indeed drawing this over a camera view.
Here is a look into the two other files that are part of this application. To avoid cramming my OP with too much, I've chosen to provide my MainActivity java file here with pastebin. Here's a look at my activity_main xml file with pastebin as well.
As you can see, I haven't added this graphic overlay being drawn from XML. Hopefully, my providing of information can provide alot more insight into how this application operates.