face_detection_app.py 文件源码

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

项目:real_time_face_detection 作者: Snowapril 项目源码 文件源码
def main(parser):
    capture = cv2.VideoCapture(parser.source)
    src_width, src_height = int(capture.get(cv2.CAP_PROP_FRAME_WIDTH)), int(capture.get(cv2.CAP_PROP_FRAME_HEIGHT))

    if(parser.record == True):
        fourcc = cv2.VideoWriter_fourcc(*'XVID')
        out = cv2.VideoWriter(parser.output_path,fourcc, 20.0, (src_width,src_height))

    cascPath = "./haarcascade_frontalface_default.xml"
    faceCascade = cv2.CascadeClassifier(cascPath)

    while True:
        ret, frame = capture.read()


        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        faces = faceCascade.detectMultiScale(
            gray,
            scaleFactor=1.1,
            minNeighbors=5,
            minSize=(30, 30),
            flags = cv2.CASCADE_SCALE_IMAGE
        )

        pred_features = detect_features(gray, faces, src_width, src_height, parser.width, parser.height)
        result_img = draw_features_point_on_image(frame, pred_features, src_width, src_height)

        for (x, y, w, h) in faces:
            cv2.rectangle(result_img, (x, y), (x+w, y+h), (0, 255, 0), 1)

        if (ret==True) and (parser.record == True):
            out.write(result_img)

        cv2.imshow('Video', result_img)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    capture.release()

    if parser.record == True:
        out.release()

    cv2.destroyAllWindows()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号