zoukankan      html  css  js  c++  java
  • 使用face_recognition批量识别图片中的人数

    #使用face_recognition实现从图片中选中人数并分别输出txt




    import
    face_recognition import cv2 import os fin = 'D:\Users\a\Pictures\test_pho' # 读取图片并识别人脸 for file in os.listdir(fin): file_fullname = fin + '/' + file img = face_recognition.load_image_file(file_fullname) face_locations = face_recognition.face_locations(img) print(face_locations) faceNum = len(face_locations) print(faceNum) num = str(faceNum) file_object = open(file_fullname+'.txt', 'w') file_object.write(num+ '个人') file_object.close() # 调用opencv函数显示图片 # img = cv2.imread("D:\Users\a\Pictures\test_pho\3.jpg") # cv2.namedWindow("pre_pho") # cv2.imshow("pre_pho", img) #遍历每个人脸,并标注 # faceNum = len(face_locations) # print(faceNum) for i in range(0, faceNum): top = face_locations[i][0] right = face_locations[i][1] bottom = face_locations[i][2] left = face_locations[i][3] start = (left, top) end = (right, bottom) color = (55, 255, 155) thickness = 3 cv2.rectangle(img, start, end, color, thickness) # 显示识别结果 # cv2.namedWindow("rec_pho") # cv2.imshow("rec_pho", img) cv2.waitKey(0) cv2.destroyAllWindows()

  • 相关阅读:
    scala 获取当前时间的两种方式
    log4j配置输出日志文件
    scala读取jar包外配置文件的方式
    scala 异常处理机制
    IDEA 安装scala插件
    第2部分 Elasticsearch查询-请求体查询、排序
    第1部分 Elasticsearch基础
    2.css
    1.html
    Linux搭建Nexus仓库+高可用方案
  • 原文地址:https://www.cnblogs.com/ansang/p/7895059.html
Copyright © 2011-2022 走看看