feat: added rotation config

This commit is contained in:
2021-01-13 21:19:03 +01:00
parent 9419544511
commit 7d46950add
4 changed files with 28 additions and 3 deletions

View File

@@ -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)