Skip to content

Commit 9c843d6

Browse files
Merge pull request #2 from 5sControl/dev
Dev
2 parents 5dae8f1 + c09c3e6 commit 9c843d6

File tree

7 files changed

+40
-13
lines changed

7 files changed

+40
-13
lines changed

.dockerignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
.cache
1+
.cache
2+
__pycache__

confs/configs.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"classes": [
3+
67
4+
],
5+
"iou_thres": 0.5,
6+
"conf_thres": 0.3,
7+
"model_path": "idle_models/idle_v0.3.11.pt",
8+
"wait_time": 10,
9+
"threshold": 100
10+
}

confs/load_configs.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import json
2+
3+
4+
with open("confs/configs.json", "r") as conf:
5+
configs = json.load(conf)
6+
CONF_THRES = configs.get("conf_thres")
7+
IOU_THRES = configs.get("iou_thres")
8+
MODEL_PATH = configs.get("model_path")
9+
CLASSES = configs.get("classes")
10+
WAIT_TIME = configs.get("wait_time")
11+
THRESHOLD = configs.get("threshold")

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.162/onvif-http/snapshot?Profile_1'
3+
camera_url = 'http://192.168.1.166/onvif-http/snapshot?Profile_1'
44
server_url = 'http://192.168.1.999'
55
folder = 'images/192.168.1.168'

functional.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
from confs.load_configs import *
22
import os
33
import uuid
44
import datetime
@@ -9,7 +9,9 @@
99
import requests
1010
import httplib2
1111
import numpy as np
12-
from ObjectDetectionModel import ObjDetectionModel
12+
from idle_models.ObjectDetectionModel import ObjDetectionModel
13+
import time
14+
from dotenv import load_dotenv
1315

1416

1517
def create_logger():
@@ -32,6 +34,9 @@ def create_logger():
3234

3335
def init_connection():
3436
password = os.environ.get("password")
37+
if password is None:
38+
load_dotenv("confs/settings.env")
39+
password = os.environ.get("password")
3540
username = os.environ.get("username")
3641
try:
3742
h = httplib2.Http(".cache")
@@ -43,7 +48,7 @@ def init_connection():
4348

4449

4550
def init_model():
46-
model = ObjDetectionModel("yolov8l.pt", 0.3, 0.5)
51+
model = ObjDetectionModel(MODEL_PATH, CONF_THRES, IOU_THRES, CLASSES)
4752
return model
4853

4954

@@ -66,7 +71,7 @@ def put_rectangle(img, boxes, scores):
6671
return img
6772

6873

69-
def check_coordinates_diffs(coords_1: np.array, coords_2: np.array, threshold=20):
74+
def check_coordinates_diffs(coords_1: np.array, coords_2: np.array, threshold=THRESHOLD):
7075
if coords_1 is None:
7176
return True
7277
diff = np.abs(coords_1 - coords_2).sum()
@@ -81,10 +86,10 @@ def send_report_and_save_photo(img0):
8186
save_photo_url = f'{folder}/' + str(uuid.uuid4()) + '.jpg'
8287
cv2.imwrite(save_photo_url, img0)
8388

84-
time_delta_seconds = 10
89+
time_delta_seconds = WAIT_TIME
8590
start_tracking = str(datetime.datetime.now())
86-
stop_tracking = str(datetime.datetime.now() +
87-
datetime.timedelta(0, time_delta_seconds))
91+
time.sleep(time_delta_seconds)
92+
stop_tracking = str(datetime.datetime.now())
8893

8994
report_for_send = {
9095
'camera': folder.split('/')[1],

ObjectDetectionModel.py renamed to idle_models/ObjectDetectionModel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44

55
class ObjDetectionModel:
6-
def __init__(self, path: str, conf_thresh, iou_thresh) -> None:
6+
def __init__(self, path: str, conf_thresh, iou_thresh, classes) -> None:
77
self.model = YOLO(path)
88
self.conf_thresh = conf_thresh
99
self.iou_thresh = iou_thresh
10-
self.classes = [67]
10+
self.classes = classes
1111

1212
@torch.no_grad()
1313
def __call__(self, img) -> list:

main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def run():
1010
logger.warning("Cannot create connection")
1111
time.sleep(1)
1212
model = init_model()
13-
logger.info("Model is initialized")
13+
logger.info("Model initialized")
1414
prev_preds = None
1515
iter_idx = 0
1616
while True:
@@ -20,7 +20,7 @@ def run():
2020
if (img := get_frame(h)) is None:
2121
logger.warning("Empty photo")
2222
continue
23-
time.sleep(0.1)
23+
time.sleep(3)
2424
preds, scores = model(img)
2525
img = put_rectangle(img, preds.numpy(), scores.numpy())
2626
if len(scores) > 0:

0 commit comments

Comments
 (0)