代码拉取完成,页面将自动刷新
import cv2
''' 基于图片的识别人脸'''
#加载分类器
face_cascade = cv2.CascadeClassifier('haarcascades/haarcascade_frontalface_default.xml')
eye_cascade = cv2.CascadeClassifier('haarcascades/haarcascade_eye.xml')
img = cv2.imread('C:\\Users\\ding\\Desktop\\1.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#得到face一个list,list包含x,y,height,width
faces = face_cascade.detectMultiScale(gray, 1.3, 5)
# img = cv2.rectangle(img, (0, 0), (10, 10), (255, 0, 0), 2)
for (x, y, w, h) in faces:
#画矩形
img = cv2.rectangle(img, (x, y), (x + w, y + h), (255, 0, 0), 2)
roi_gray = gray[y:y + h, x:x + w]
roi_color = img[y:y + h, x:x + w]
eyes = eye_cascade.detectMultiScale(roi_gray)
# for (ex, ey, ew, eh) in eyes:
# cv2.rectangle(roi_color, (ex, ey), (ex + ew, ey + eh), (0, 255, 0), 2)
#窗口名称,以及宽、高度
cv2.namedWindow("img", 0);
cv2.resizeWindow("img", 700, 700);
cv2.imshow('img', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。