feat: added facial recognition
This commit is contained in:
@@ -4,6 +4,10 @@ from typing import Optional
|
|||||||
import cv2
|
import cv2
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
|
|
||||||
|
FACE_DATA = 'haarcascade_frontalface_default.xml'
|
||||||
|
|
||||||
|
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + FACE_DATA)
|
||||||
|
|
||||||
|
|
||||||
class Camera:
|
class Camera:
|
||||||
capture: cv2.VideoCapture
|
capture: cv2.VideoCapture
|
||||||
@@ -15,6 +19,12 @@ class Camera:
|
|||||||
return_code, image = self.capture.read()
|
return_code, image = self.capture.read()
|
||||||
if not return_code:
|
if not return_code:
|
||||||
return None
|
return None
|
||||||
|
image_gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
||||||
|
|
||||||
|
faces = face_cascade.detectMultiScale(image_gray, 1.3, 5)
|
||||||
|
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)
|
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
||||||
jpg = Image.fromarray(image_rgb)
|
jpg = Image.fromarray(image_rgb)
|
||||||
byte_stream = BytesIO()
|
byte_stream = BytesIO()
|
||||||
|
|||||||
Reference in New Issue
Block a user