import cv2
filepath = "C:/Users/ming/Desktop/astronaut.jpg"
img = cv2.imread(filepath)
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
classifier = cv2.CascadeClassifier(
"D:\python\haarcascades\haarcascade_frontalface_alt.xml"
)
color = (0, 255, 0)
faceRects = classifier.detectMultiScale(
gray, scaleFactor=1.2, minNeighbors=3, minSize=(32, 32))
if len(faceRects):
for faceRect in faceRects:
x, y, w, h = faceRect
cv2.rectangle(img, (x, y), (x + h, y + w), color, 2)
cv2.imshow("image", img)
c = cv2.waitKey(10)
cv2.waitKey(0)
cv2.destroyAllWindows()
