Skip to content

Commit

Permalink
Merge pull request #10 from 5sControl/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
eugenos-programos authored Aug 2, 2023
2 parents 4abbed3 + 44d3898 commit 5676eb2
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
2 changes: 1 addition & 1 deletion confs/settings.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
username = 'admin'
password = 'just4Taqtile'
camera_url = 'http://192.168.1.110:3456/onvif-http/snapshot?camera_ip=192.168.1.168'
camera_url = 'http://192.168.1.110/images/192.168.1.169/snapshot.jpg'
server_url = 'http://127.0.0.1'
folder = 'images/192.168.1.163'
22 changes: 11 additions & 11 deletions connection/ImageHTTPExtractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ def __init__(self, server_url: str, logger: logging.Logger, **credentials) -> No

def get_snapshot(self) -> Tuple[Union[cv2.Mat, None], Union[datetime.time, None]]:
try:
curr_time = datetime.datetime.now()
response, content = self.http_connection.request(
self.server_url,
"GET",
body="foobar"
)
nparr = np.frombuffer(content, np.uint8)
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
return img, curr_time
curr_time = datetime.datetime.now()
response, content = self.http_connection.request(
self.server_url,
"GET",
body="foobar"
)
nparr = np.frombuffer(content, np.uint8)
img = cv2.imdecode(nparr, cv2.IMREAD_COLOR)
return img, curr_time
except Exception as exc:
self.logger.error(f"Cannot retrieve image. Following error raised - {exc}")
return None, None
self.logger.error(f"Cannot retrieve image. Following error raised - {exc}")
return None, None
4 changes: 2 additions & 2 deletions connection/ModelPredictionsReceiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def predict(self, img: np.array) -> np.array:
}
)
response.raise_for_status()
return np.array(response.json().get("coordinates"))
return np.array(response.json().get("coordinates")).astype(np.float32)
except Exception as exc:
self.logger.critical("Cannot send request to model server. Error - {}".format(exc))
return np.array([])
return np.array([[]])
2 changes: 1 addition & 1 deletion idle_model/configs/confs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
67
],
"iou_thres": 0.5,
"conf_thres": 0.5,
"conf_thres": 0.6,
"model_path": "weights/idle_v0.4.4.pt",
"conf_path": "weights/yolor_csp_x.cfg",
"port": 5001
Expand Down
4 changes: 2 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

logger = utils.create_logger()

prev_preds = None
prev_preds = np.array([[]]).astype(np.float32)
reporter = connection.IdleReporter(folder, server_url, configs["wait_time"], logger)
image_extractor = connection.ImageHTTPExtractor(camera_url, logger, username=username, password=password)
model_predictor = connection.ModelPredictionsReceiver(server_url, logger)
Expand All @@ -37,7 +37,7 @@
if preds is None:
time.sleep(1)
continue
if preds.size != 0 and np.any(preds[:, -1] == 1.):
if preds.size != 0 and not np.any(preds == 1.):
logger.info("Telephone is detected")
if utils.are_bboxes_equal(prev_preds, preds, configs["threshold"]):
img = utils.put_rectangle(img, preds[:, :4], preds[:, 4])
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ pydantic==1.10.2
python-dotenv==1.0.0
PyYAML==6.0
requests==2.27.1
numba==0.57.1
7 changes: 4 additions & 3 deletions utils/functional.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import cv2
import numpy as np
import numba


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


def are_bboxes_equal(coords_1: np.array, coords_2: np.array, threshold) -> bool:
@numba.njit(numba.boolean(numba.float32[:, :], numba.float32[:, :], numba.float32), parallel=True)
def are_bboxes_equal(coords_1: np.array, coords_2: np.array, threshold: float) -> bool:
if coords_1 is None or coords_1.shape != coords_2.shape:
return True
diff = np.abs(coords_1 - coords_2).sum()
return diff > threshold
return np.abs(coords_1 - coords_2).sum() > threshold

0 comments on commit 5676eb2

Please sign in to comment.