Skip to content

Commit 5676eb2

Browse files
Merge pull request #10 from 5sControl/dev
Dev
2 parents 4abbed3 + 44d3898 commit 5676eb2

File tree

7 files changed

+22
-20
lines changed

7 files changed

+22
-20
lines changed

confs/settings.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
username = 'admin'
22
password = 'just4Taqtile'
3-
camera_url = 'http://192.168.1.110:3456/onvif-http/snapshot?camera_ip=192.168.1.168'
3+
camera_url = 'http://192.168.1.110/images/192.168.1.169/snapshot.jpg'
44
server_url = 'http://127.0.0.1'
55
folder = 'images/192.168.1.163'

connection/ImageHTTPExtractor.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ def __init__(self, server_url: str, logger: logging.Logger, **credentials) -> No
1515

1616
def get_snapshot(self) -> Tuple[Union[cv2.Mat, None], Union[datetime.time, None]]:
1717
try:
18-
curr_time = datetime.datetime.now()
19-
response, content = self.http_connection.request(
20-
self.server_url,
21-
"GET",
22-
body="foobar"
23-
)
24-
nparr = np.frombuffer(content, np.uint8)
25-
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
26-
return img, curr_time
18+
curr_time = datetime.datetime.now()
19+
response, content = self.http_connection.request(
20+
self.server_url,
21+
"GET",
22+
body="foobar"
23+
)
24+
nparr = np.frombuffer(content, np.uint8)
25+
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
26+
return img, curr_time
2727
except Exception as exc:
28-
self.logger.error(f"Cannot retrieve image. Following error raised - {exc}")
29-
return None, None
28+
self.logger.error(f"Cannot retrieve image. Following error raised - {exc}")
29+
return None, None

connection/ModelPredictionsReceiver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def predict(self, img: np.array) -> np.array:
3030
}
3131
)
3232
response.raise_for_status()
33-
return np.array(response.json().get("coordinates"))
33+
return np.array(response.json().get("coordinates")).astype(np.float32)
3434
except Exception as exc:
3535
self.logger.critical("Cannot send request to model server. Error - {}".format(exc))
36-
return np.array([])
36+
return np.array([[]])

idle_model/configs/confs.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
67
44
],
55
"iou_thres": 0.5,
6-
"conf_thres": 0.5,
6+
"conf_thres": 0.6,
77
"model_path": "weights/idle_v0.4.4.pt",
88
"conf_path": "weights/yolor_csp_x.cfg",
99
"port": 5001

main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
logger = utils.create_logger()
2020

21-
prev_preds = None
21+
prev_preds = np.array([[]]).astype(np.float32)
2222
reporter = connection.IdleReporter(folder, server_url, configs["wait_time"], logger)
2323
image_extractor = connection.ImageHTTPExtractor(camera_url, logger, username=username, password=password)
2424
model_predictor = connection.ModelPredictionsReceiver(server_url, logger)
@@ -37,7 +37,7 @@
3737
if preds is None:
3838
time.sleep(1)
3939
continue
40-
if preds.size != 0 and np.any(preds[:, -1] == 1.):
40+
if preds.size != 0 and not np.any(preds == 1.):
4141
logger.info("Telephone is detected")
4242
if utils.are_bboxes_equal(prev_preds, preds, configs["threshold"]):
4343
img = utils.put_rectangle(img, preds[:, :4], preds[:, 4])

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ pydantic==1.10.2
88
python-dotenv==1.0.0
99
PyYAML==6.0
1010
requests==2.27.1
11+
numba==0.57.1

utils/functional.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import cv2
22
import numpy as np
3+
import numba
34

45

56
def put_rectangle(img: cv2.Mat, boxes: list, scores: list) -> np.array:
@@ -10,8 +11,8 @@ def put_rectangle(img: cv2.Mat, boxes: list, scores: list) -> np.array:
1011
return img
1112

1213

13-
def are_bboxes_equal(coords_1: np.array, coords_2: np.array, threshold) -> bool:
14+
@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:
1416
if coords_1 is None or coords_1.shape != coords_2.shape:
1517
return True
16-
diff = np.abs(coords_1 - coords_2).sum()
17-
return diff > threshold
18+
return np.abs(coords_1 - coords_2).sum() > threshold

0 commit comments

Comments
 (0)