Skip to content

Commit 75180ea

Browse files
Merge pull request #11 from 5sControl/dev
Dev
2 parents 5676eb2 + 151baf0 commit 75180ea

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

main.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,11 @@
3939
continue
4040
if preds.size != 0 and not np.any(preds == 1.):
4141
logger.info("Telephone is detected")
42-
if utils.are_bboxes_equal(prev_preds, preds, configs["threshold"]):
42+
if utils.bboxes_not_equal(prev_preds, preds, configs["threshold"]):
43+
utils.save_cropped_bbox(img, preds[:, :4])
4344
img = utils.put_rectangle(img, preds[:, :4], preds[:, 4])
4445
reporter.send_report(reporter.create_report(img, str(start_tracking)))
46+
else:
47+
logger.debug("Equal bboxes")
4548
prev_preds = preds
4649
time.sleep(2)

utils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
from .functional import put_rectangle, are_bboxes_equal
1+
from .functional import put_rectangle, bboxes_not_equal, save_cropped_bbox
22
from .logger import create_logger

utils/functional.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import cv2
22
import numpy as np
33
import numba
4+
import os
5+
import uuid
46

57

68
def put_rectangle(img: cv2.Mat, boxes: list, scores: list) -> np.array:
@@ -12,7 +14,14 @@ def put_rectangle(img: cv2.Mat, boxes: list, scores: list) -> np.array:
1214

1315

1416
@numba.njit(numba.boolean(numba.float32[:, :], numba.float32[:, :], numba.float32), parallel=True)
15-
def are_bboxes_equal(coords_1: np.array, coords_2: np.array, threshold: float) -> bool:
17+
def bboxes_not_equal(coords_1: np.array, coords_2: np.array, threshold: float) -> bool:
1618
if coords_1 is None or coords_1.shape != coords_2.shape:
1719
return True
1820
return np.abs(coords_1 - coords_2).sum() > threshold
21+
22+
def save_cropped_bbox(img: np.array, bboxes: np.array):
23+
os.makedirs("images/debug/", exist_ok=True)
24+
for bbox in bboxes:
25+
x1, y1, x2, y2 = bbox.astype(int)
26+
c = 15
27+
cv2.imwrite(f"images/debug/{uuid.uuid4()}.png", img[x1 - c:x2 + c, y1 - c:y2 + c])

0 commit comments

Comments
 (0)