BUG: Fixes and cleanup around region / bounding box calculation (#3879)

* -1 so ensure indexes are correct

* Catch case of zero division

* Due to the -1, it may be negative

* Ignore source of error

The error is occurring due to a detections bounding box starting beyond the frame, this should be immediately ignored

* Formatting

* Check horizontal placement as well

* Remove original frame clamping
This commit is contained in:
Nicolas Mowen 2022-09-22 07:07:16 -06:00 committed by GitHub
parent faf583451f
commit df40b96b44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -457,8 +457,13 @@ def detect(
size = region[2] - region[0] size = region[2] - region[0]
x_min = int(max(0, (box[1] * size) + region[0])) x_min = int(max(0, (box[1] * size) + region[0]))
y_min = int(max(0, (box[0] * size) + region[1])) y_min = int(max(0, (box[0] * size) + region[1]))
x_max = int(min(detect_config.width, (box[3] * size) + region[0])) x_max = int(min(detect_config.width - 1, (box[3] * size) + region[0]))
y_max = int(min(detect_config.height, (box[2] * size) + region[1])) y_max = int(min(detect_config.height - 1, (box[2] * size) + region[1]))
# ignore objects that were detected outside the frame
if (x_min >= detect_config.width - 1) or (y_min >= detect_config.height - 1):
continue
width = x_max - x_min width = x_max - x_min
height = y_max - y_min height = y_max - y_min
area = width * height area = width * height
@ -657,10 +662,10 @@ def process_frames(
# apply max/min to ensure values do not exceed the known frame size # apply max/min to ensure values do not exceed the known frame size
boxes = [ boxes = [
( (
max(o[2][0], 0), o[2][0],
max(o[2][1], 0), o[2][1],
min(o[2][2] - o[2][0], detect_config.width - 1), o[2][2] - o[2][0],
min(o[2][3] - o[2][1], detect_config.height - 1), o[2][3] - o[2][1],
) )
for o in group for o in group
] ]