Skip to content

Commit

Permalink
Merge pull request #15 from 5sControl/hot_fix
Browse files Browse the repository at this point in the history
Intersection fix
  • Loading branch information
oleg-nai authored Jul 25, 2023
2 parents 205e3c0 + 5b7a777 commit 8acec50
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
8 changes: 6 additions & 2 deletions machine_control_utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,12 @@ def get_intersection(box_a, box_b, threshold=0.25):
lb, tb, rb, bb = box_b
l, t, r, b = max(la, lb), max(ta, tb), min(ra, rb), min(ba, bb)

human_area = (ra - la + 1) * (ba - ta + 1)
box_area = (rb - lb + 1) * (bb - tb + 1)
intersection_area = (r - l + 1) * (b - t + 1)
intersection_area = max(0, (r - l + 1)) * max(0, (b - t + 1))

intersection_box = intersection_area / box_area
if box_area > human_area:
intersection_box = intersection_area / human_area
else:
intersection_box = intersection_area / box_area
return intersection_box > threshold
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import warnings
from dotenv import load_dotenv

load_dotenv()
load_dotenv('config/.env')

warnings.filterwarnings("ignore")

Expand Down
3 changes: 2 additions & 1 deletion run.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ def run_machine_control(model: YoloDetector, img, areas_data: List[Area]):
elif len(areas_data[i]) == 3:
if datetime.now() - areas_data[i].date[0] > timedelta(minutes=30):
areas_data[i].refresh()
areas_data[i].update(img)
else:
areas_data[i].update(img)

if not in_area:
if len(areas_data[i]) == 1:
Expand Down

0 comments on commit 8acec50

Please sign in to comment.