MeeraWeeks
MeeraWeeks

Reputation: 93

Negative location for TFLite detection results

Using custom model, I'm trying to locate some object on a bitmap but I get negative values for location box

e.g. my bitmap size:

myBitmap.getHeight() = 129
myBitmap.getWidth() = 202

but the results are:

item (91,4%) RectF(-0.48639297, 5.0847816, 321.28015, 190.07951)
item (10,9%) RectF(9.338188, 86.65706, 315.48764, 350.3579)

where the location is sometimes a negative number and even if it's not, the location has has values that make no sense to me. (Value result.bottom is 321, while my bitmap's height is only 129.

What am I doing wrong here? Is it the model's problem or am I interpreting the results wrong?

EDIT: Okay, I figured out that the difference in scale probably comes from the fact that results are in pixel but bitmap height and width are in dp.

But what about negative results?

Upvotes: 1

Views: 538

Answers (1)

Zahra Nikdel
Zahra Nikdel

Reputation: 21

You're not doing anything wrong, just need to find the correct coordination: imH, imW are your image's height and width

ymin = int(max(1,(RectF[0] * imH)))
xmin = int(max(1,(RectF[1] * imW)))
ymax = int(min(imH,(RectF[2] * imH)))
xmax = int(min(imW,(RectF[3] * imW)))

Upvotes: 2

Related Questions