feat: fixed bug in camera code

This commit is contained in:
2021-01-17 20:14:17 +01:00
parent 049cc72ecd
commit e834335e27

View File

@@ -1,6 +1,7 @@
import configparser
import os.path
from io import BytesIO
from pprint import pprint
from typing import NamedTuple, Optional, Tuple
import cv2
@@ -46,7 +47,7 @@ class Camera:
self.rotate = get_rotate_value(self.config['rotate'])
self.detect_face = False
self.detect_face = True
self.draw_face = self.config.getboolean('draw_face', fallback=False)
def get_image(self) -> Tuple[Optional[bytes], Optional[FacePos]]:
@@ -60,10 +61,11 @@ class Camera:
if self.detect_face:
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(image_gray, 1.3, 5)
face = FacePos(*faces[0])
if self.draw_face:
for (x, y, w, h) in faces:
image = cv2.rectangle(image, (x, y), (x + w, y + h), (255, 0, 0), 2)
if faces is not None and len(faces) > 0:
face = FacePos(*faces[0])
if self.draw_face:
for (x, y, w, h) in faces:
image = cv2.rectangle(image, (x, y), (x + w, y + h), (255, 0, 0), 2)
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
jpg = Image.fromarray(image_rgb)