diff --git a/.gitignore b/.gitignore index a8054db..e4ad77c 100644 --- a/.gitignore +++ b/.gitignore @@ -221,4 +221,6 @@ yarn-error.log # custom .idea/ -sounds/ \ No newline at end of file +sounds/ + +config.ini \ No newline at end of file diff --git a/client/src/main.js b/client/src/main.js index e460a6a..8818681 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -6,9 +6,9 @@ import router from './router'; Vue.use(new VueSocketIO({ debug: false, - connection: SocketIO(`${window.location.protocol}//${window.location.host}`), + connection: SocketIO(`${window.location.protocol}//${window.location.host}`, { transports: ['websocket'] }), options: { - transport: 'websocket', + transports: ['websocket'], }, })); diff --git a/config.example.ini b/config.example.ini new file mode 100644 index 0000000..474f251 --- /dev/null +++ b/config.example.ini @@ -0,0 +1,2 @@ +[camera] +rotate=0 \ No newline at end of file diff --git a/control/camera.py b/control/camera.py index 02c4183..1a07ad8 100644 --- a/control/camera.py +++ b/control/camera.py @@ -1,6 +1,7 @@ from io import BytesIO import os.path from typing import Optional +import configparser import cv2 from PIL import Image @@ -13,16 +14,36 @@ FACE_DATA = next(filter(os.path.exists, [ face_cascade = cv2.CascadeClassifier(FACE_DATA) +def get_rotate_value(input_value): + if input_value == '0': + return None + + if input_value == '90': + return cv2.ROTATE_90_CLOCKWISE + if input_value == '-90' or input_value == '270': + return cv2.ROTATE_90_COUNTERCLOCKWISE + if input_value == '180': + return cv2.ROTATE_180 + raise ValueError(f"Unsupported rotation value {input_value!r}") + + class Camera: capture: cv2.VideoCapture def __init__(self): self.capture = cv2.VideoCapture(0) + parser = configparser.ConfigParser() + parser.read('config.ini') + self.config = parser['camera'] + + self.rotate = get_rotate_value(self.config['rotate']) def get_image(self) -> Optional[bytes]: return_code, image = self.capture.read() if not return_code: return None + if self.rotate is not None: + image = cv2.rotate(image, self.rotate) image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) faces = face_cascade.detectMultiScale(image_gray, 1.3, 5)