Last active
July 20, 2022 10:22
-
-
Save Priler/46591485036444e0c684f93674b28c09 to your computer and use it in GitHub Desktop.
Face detection using Python OpenCV2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import sys | |
imgPath = input("Введите путь к картинке:") | |
faceCascade = cv2.CascadeClassifier( | |
cv2.data.haarcascades+'haarcascade_frontalface_default.xml') | |
img = cv2.imread(imgPath) | |
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
faces = faceCascade.detectMultiScale( | |
imgGray, | |
scaleFactor = 1.1, | |
minNeighbors = 7, | |
minSize = (30, 30), | |
flags = cv2.CASCADE_SCALE_IMAGE | |
) | |
print(f"Найдено лиц: {len(faces)}") | |
if(len(faces)): | |
print("Вывожу на экран ...") | |
for(x, y, w, h) in faces: | |
cv2.rectangle(img, (x, y), (x+w, y+h), (255, 0, 0), 5) | |
cv2.imshow("Найденные лица", img) | |
cv2.waitKey(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment