Skip to content

Commit fe471dd

Browse files
perf($OpenCV): change dependency to opencv-python-headless==4.5.4.58
Packages for server (headless) environments (such as Docker, cloud environments etc.), no GUI library dependencies. Headless main modules package: pip install opencv-python-headless Headless full package (contains both main modules and contrib/extra modules): pip install opencv-contrib-python-headless https://pypi.org/project/opencv-python-headless/4.5.4.58/
1 parent c4da662 commit fe471dd

4 files changed

Lines changed: 53 additions & 44 deletions

File tree

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ python_version = "3.10"
99
[packages]
1010
peewee = "==3.14.8"
1111
loguru = "==0.5.3"
12-
opencv-python = "==4.5.4.58"
12+
opencv-python-headless = "==4.5.4.58"
1313
pyhocon = "==0.3.58"
1414
jinja2 = "==3.0.3"
1515

Pipfile.lock

Lines changed: 33 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

home_guardian/__main__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1+
from loguru import logger
2+
13
from home_guardian.configuration.thread_pool_configuration import (
24
cleanup as thread_pool_cleanup,
35
)
4-
from home_guardian.configuration.thread_pool_configuration import simulate_multi_thread
5-
6-
7-
def cleanup() -> None:
8-
thread_pool_cleanup()
6+
from home_guardian.opencv.face_detection import detect_and_take_photo
97

108

11-
def main() -> None:
9+
def _main() -> None:
1210
"""
1311
Main function.
1412
"""
1513
try:
16-
simulate_multi_thread()
14+
detect_and_take_photo()
1715
finally:
18-
cleanup()
16+
# Cleanup procedures
17+
logger.warning("Cleaning up…")
18+
thread_pool_cleanup()
1919

2020

2121
if __name__ == "__main__":
22-
main()
22+
_main()

home_guardian/opencv/face_detection.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
from time import sleep
44

5+
# noinspection PyPackageRequirements
56
import cv2.cv2 as cv2
67
from loguru import logger
78

@@ -18,10 +19,18 @@
1819

1920

2021
def detect_and_take_photo() -> None:
22+
"""
23+
Detect and take photo.
24+
:return: when exception is raised, return None.
25+
"""
2126
face = cv2.CascadeClassifier(
2227
f"{get_resources_dir()}/haarcascade_frontalface_alt2.xml"
2328
)
24-
capture = cv2.VideoCapture(0)
29+
try:
30+
capture = cv2.VideoCapture(0)
31+
except Exception as e:
32+
logger.error("Exception raised while capturing video!", e)
33+
return
2534
while True:
2635
return_value, frame = capture.read()
2736
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

0 commit comments

Comments
 (0)