Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correction to IOU calcuation #195

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions src/grits.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,12 +227,9 @@ def iou(bbox1, bbox2):
Compute the intersection-over-union of two bounding boxes.
"""
intersection = Rect(bbox1).intersect(bbox2)
union = Rect(bbox1).include_rect(bbox2)

union_area = union.get_area()
union_area = Rect(bbox1).get_area() + Rect(bbox2).get_area() - intersection.get_area()
if union_area > 0:
return intersection.get_area() / union.get_area()

return intersection.get_area() / union_area
return 0


Expand Down
16 changes: 2 additions & 14 deletions src/postprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

from fitz import Rect

from grits import iou


def apply_threshold(objects, threshold):
"""
Expand All @@ -31,20 +33,6 @@ def apply_class_thresholds(bboxes, labels, scores, class_names, class_thresholds
return bboxes, scores, labels


def iou(bbox1, bbox2):
"""
Compute the intersection-over-union of two bounding boxes.
"""
intersection = Rect(bbox1).intersect(bbox2)
union = Rect(bbox1).include_rect(bbox2)

union_area = union.get_area()
if union_area > 0:
return intersection.get_area() / union.get_area()

return 0


def iob(bbox1, bbox2):
"""
Compute the intersection area over box area, for bbox1.
Expand Down