#opencv对图像进行预处理 import cv2 import numpy as np #xml文件的加载 face_xml = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') eye_xml = cv2.CascadeClassifier('haarcascade_exye,xml') img = cv2.imread('face.jpg') cv2.imshow('src', img) #彩色图片到灰色图片的转化 gray = cv2.cvtColor(img, cvw.COLOR_BGR2GRAY) #人脸检测 faces = face_xml.detectMultiScale(gray, 1.3, 5) index = 0 print('face=', len(faces)) #图像绘制#for# , y, w, h) in faces : cv2.recentangle(img, (x, y), (x+w, y+h),(255, 0,0,),2) roi_face = gray[y:y+h,x:x+w] #当前检测的人脸 roi_cocor = img[y:y+h,x:x+w] #当前检测的人脸彩色 fileName = index+'.str' index = index eyes = eye_xml.detectMultiScale(roi_face) print('eye=',len(eyes)) cv2.imshow('dst',img) cv2.waitKey(0)