def findfaces(image):
thisdirectory = os.path.dirname(os.path.realpath(__file__))
haarcascadeFolder = os.path.join(thisdirectory,"haarcascades")
cascPath = os.path.join(haarcascadeFolder, "haarcascade_frontalface_default.xml")
#cascPath = os.path.join(haarcascadeFolder, "haarcascade_upperbody.xml")
#cascPath = os.path.join(haarcascadeFolder, "haarcascade_fullbody.xml")
#cascPath = os.path.join(haarcascadeFolder, "haarcascade_russian_plate_number.xml")
# Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)
# Read the image
height, width, depth = image.shape
scale = 1
if (width > 1024):
scale = 1024.0/width
image = cv2.resize(image, None, fx=scale, fy=scale)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Detect faces in the image
faces = faceCascade.detectMultiScale(
gray,
scaleFactor=1.05,
minNeighbors=5,
minSize=(30, 30),
)
return [scale_rect(face, 1/scale) for face in faces]
评论列表
文章目录