Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

Drawing rectangles wrong

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My application uses Google ML to detect objects by drawing rectangles (BoundingBox) around the object it detects. However, this
 is what it ends up looking like. The problem is that the rectangle is drawn above the object it's suppose to be drawn around. It's come to my attention that the focus is on the code and not on the library.

I've built this application using this CameraX documentation to build the camera stream preview from my device camera. I then used this Google ML documentation to get the application to build and track objects. However, it's come to my attention that I'm drawing the rectangles wrong, and I wish to know how exactly I can resolve that. I will provide the code for my DrawGraphic.java class and my MainActivity.java class. Any further information needed to supplement the question can be provided upon request!

Here is the DrawGraphic.java class that draws the rectangle;


 
Saloon Keeper
Posts: 24188
166
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I can't give you an exact answer, but in general, GUI systems work by a set of rectangular (viewport) areas. Often the co-ordinates of an inner area are relative to the area that contains it, not to the absolute screen rectangle that contains them all. So you might start with that approach.

Swing has a co-ordinate translation/rotation/scaling service that often applies to stuff like this.
 
Master Rancher
Posts: 4457
38
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What code creates the Rect object?  It looks like the x values are ok.  The y values not so good.
 
Mason Buchanan
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Norm Radder, Line 123 of the following code is where the Rect is called and created. I was originally only going to put in that method only. However, I find that including everything first and isolating the root of the problem later can help. So here it is. Also, since you said the x values are ok, and y values aren't looking so good, how would I fix that?

 
Norm Radder
Master Rancher
Posts: 4457
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok then backtracking it looks like the Rect's value comes from a detectedObjects object around line 82.  
 
I can't renounce my name. It's on all my stationery! And hinted in this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic