Selected Generalize Function For Face Detection MTCNN
Selected Generalize Function For Face Detection MTCNN
Code
mtcnn = MTCNN(keep_all=True)
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
boxes, _ = mtcnn.detect(frame)
cap.release()
cv2.destroyAllWindows()
Haar cascade
import cv2 # Import the OpenCV library
# Break the loop and close the window when 'q' key is pressed
if cv2.waitKey(1) & 0xFF == ord('q'):
break
DLIB
import cv2
import dlib
detector = dlib.get_frontal_face_detector()
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = detector(gray)
for face in faces:
x, y, w, h = (face.left(), face.top(), face.width(), face.height())
cv2.rectangle(frame, (x, y), (x+w, y+h), (255, 255, 255), 2)
cap.release()
cv2.destroyAllWindows()
YOLO
import cv2
import numpy as np
# Load YOLO
net = cv2.dnn.readNet('yolov3.weights', 'yolov3.cfg')
layer_names = net.getLayerNames()
output_layers = [layer_names[i - 1] for i in net.getUnconnectedOutLayers()]
while True:
ret, frame = cap.read()
height, width, _ = frame.shape # Get frame dimensions