2092240e04
Date: 20240427 Design by JRNitre
17 lines
551 B
Python
17 lines
551 B
Python
import cv2
|
|
|
|
img = cv2.imread("source/data_02.jpg")
|
|
|
|
faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
|
|
|
|
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
|
|
|
faces = faceCascade.detectMultiScale(gray, scaleFactor=1.09, minNeighbors=3, minSize=(5, 5))
|
|
print(faces)
|
|
print("该图一共有{0}人脸".format(len(faces)))
|
|
for(x, y, w, h) in faces:
|
|
cv2.circle(img, (int((2 * x + w) / 2), int((2 * y + h) / 2)),
|
|
int(w / 2), (0, 255, 0), 2)
|
|
cv2.imshow("result", img)
|
|
cv2.waitKey()
|
|
cv2.destroyWindow() |