11-amaliy mashg’ulot Mavzu: 8.Neyron tarmog‘ining kaskadli modeli Amaliy qism: Code: import cv2
from matplotlib import pyplot as plt
from mtcnn.mtcnn import MTCNN
# Load an image
image_path = 'eye_image.jpg'
pixels = cv2.imread(image_path)
# Create an MTCNN detector
detector = MTCNN()
# Detect faces in the image
faces = detector.detect_faces(pixels)
# Display the original image
plt.imshow(cv2.cvtColor(pixels, cv2.COLOR_BGR2RGB))
ax = plt.gca()
# Draw boxes around the faces and facial landmarks
for face in faces:
x, y, width, height = face['box']
rect = plt.Rectangle((x, y), width, height, fill=False, color='red')
ax.add_patch(rect)
for key, value in face['keypoints'].items():
dot = plt.Circle(value, radius=2, color='red')
ax.add_patch(dot)