资源简介

基于Linux环境下的实现

资源截图

代码片段和文件信息

import face_recognition
import pandas as pd
import numpy as np
import cv2
import os
face_db = pd.read_excel(r‘./face_recognition_images_db/face_db.xlsx‘)
if face_db.empty:
    col_name = [‘Name‘‘Path‘]
    [col_name.append(str(i)) for i in range(1129)]
    face_db = pd.Dataframe(columns=col_name)
    for root _ files in os.walk(‘./face_recognition_images_db/train_db/‘):
        for idxfile in enumerate(sorted(files)):
            face_db.loc[idx ‘Name‘] = file.split(‘.‘)[0]
            tmp_path = os.path.join(rootfile)
            face_db.loc[idx ‘Path‘] = tmp_path
            tmp_img = cv2.imread(tmp_path)[::::-1]    # BGR o RGB
            tmp_face = face_recognition.face_locations(tmp_img)     # detect face area,hog & cnn
            tmp_face_encode = face_recognition.face_encodings(tmp_imgtmp_face)[0]
            face_db.loc[idx ‘1‘:‘128‘] = np.array(tmp_face_encode)
    face_db.to_excel(r‘./face_recognition_images_db/face_db.xlsx‘index=False)

capture = cv2.VideoCapture(0)
if not capture.isOpened():
    raise IOError(‘Camera Open ErrorPlease Check...‘)

while True:
    retframe = capture.read()
    frame = cv2.resize(frame(00)fx=0.5fy=0.5)

    frame_rgb = frame[::::-1]
    faces_loc = face_recognition.face_locations(frame_rgb)
    faces_encode = face_recognition.face_encodings(frame_rgbfaces_loc)
    for (toprightbottomleft)face_encode in zip(faces_locfaces_encode):
        matches = face_recognition.compare_faces(list(face_db.loc[:‘1‘:‘128‘].values)face_encodetolerance=0.55)
        distances = face_recognition.face_distance(list(face_db.loc[:‘1‘:‘128‘].values)face_encode)
        min_distance_idx = np.argmin(distances)
        name = ‘Unknow‘
        if matches[min_distance_idx]:
            name = face_db.loc[min_distance_idx‘Name‘]

        cv2.rectangle(frame(lefttop)(rightbottom)(02550)3)
        cv2.rectangle(frame(leftbottom-30)(rightbottom)(00255)3)
        cv2.putText(framename(left+10bottom-10)cv2.FONT_HERSHEY_SIMPLEX1(255255255))
    cv2.imshow(‘face recognition‘frame)

    if cv2.waitKey(5) & 0xFF==27:
        break

capture.release()
cv2.destroyAllWindows()

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2021-03-16 12:52  python_warkspace\
     目录           0  2021-03-16 12:52  python_warkspace\.idea\
     文件          47  2021-03-13 08:34  python_warkspace\.idea\.gitignore
     文件           7  2021-03-13 09:22  python_warkspace\.idea\.name
     目录           0  2021-03-16 12:52  python_warkspace\.idea\inspectionProfiles\
     文件         174  2021-03-13 08:34  python_warkspace\.idea\inspectionProfiles\profiles_settings.xml
     文件         185  2021-03-13 08:34  python_warkspace\.idea\misc.xml
     文件         284  2021-03-13 08:34  python_warkspace\.idea\modules.xml
     文件         284  2021-03-13 08:34  python_warkspace\.idea\python_warkspace.iml
     文件        4103  2021-03-15 01:15  python_warkspace\.idea\workspace.xml
     文件        2173  2021-03-15 01:19  python_warkspace\face_recognition_demo.py
     目录           0  2021-03-16 12:52  python_warkspace\face_recognition_images_db\
     文件       12729  2021-03-15 01:21  python_warkspace\face_recognition_images_db\face_db.xlsx
     目录           0  2021-03-16 12:52  python_warkspace\face_recognition_images_db\test_db\
     文件      433621  2021-03-14 09:41  python_warkspace\face_recognition_images_db\test_db\2021-03-14 17-41-53 的屏幕截图.png
     文件      433816  2021-03-14 09:43  python_warkspace\face_recognition_images_db\test_db\2021-03-14 17-43-26 的屏幕截图.png
     文件      216357  2021-03-14 09:45  python_warkspace\face_recognition_images_db\test_db\2021-03-14 17-45-09 的屏幕截图.png
     文件      370629  2021-03-14 09:46  python_warkspace\face_recognition_images_db\test_db\2021-03-14 17-46-18 的屏幕截图.png
     文件      372656  2021-03-14 09:46  python_warkspace\face_recognition_images_db\test_db\2021-03-14 17-46-32 的屏幕截图.png
     文件      682796  2021-03-14 09:46  python_warkspace\face_recognition_images_db\test_db\2021-03-14 17-46-44 的屏幕截图.png
     文件      219307  2021-03-14 09:48  python_warkspace\face_recognition_images_db\test_db\2021-03-14 17-48-28 的屏幕截图.png
     文件      287125  2021-03-14 09:49  python_warkspace\face_recognition_images_db\test_db\2021-03-14 17-49-28 的屏幕截图.png
     文件      328747  2021-03-14 09:51  python_warkspace\face_recognition_images_db\test_db\2021-03-14 17-51-09 的屏幕截图.png
     文件      280548  2021-03-14 09:51  python_warkspace\face_recognition_images_db\test_db\2021-03-14 17-51-45 的屏幕截图.png
     目录           0  2021-03-16 12:52  python_warkspace\face_recognition_images_db\train_db\
     文件      428878  2021-03-14 09:42  python_warkspace\face_recognition_images_db\train_db\ID001_liudehua.png
     文件      347455  2021-03-14 09:46  python_warkspace\face_recognition_images_db\train_db\ID002_guofuchengpng
     文件       84128  2021-03-15 09:12  python_warkspace\face_recognition_images_db\train_db\ID004_leicunkuan.jpg
     文件      130986  2021-03-15 09:13  python_warkspace\face_recognition_images_db\train_db\ID005_luneng.jpg
     文件           0  2021-03-14 14:06  python_warkspace\test.py

评论

共有 条评论