bodydetector.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:bib-tagger 作者: KateRita 项目源码 文件源码
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]
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号