gpt4 book ai didi

opencv - 由于 numpy 在 face_recognition 中发生错误

转载 作者:太空宇宙 更新时间:2023-11-03 21:51:02 25 4
gpt4 key购买 nike

import face_recognition
import cv2
import os, os.path
import numpy as np

count = 0

def finding_members():
finding_members.list= os.listdir('/Users/apple/Desktop/face_id/train_models')
print(finding_members.list)
video_capture = cv2.VideoCapture(0)
count = 0
count1 = 0
encoding_name = str()
face_encoding = []
length_of_encoding = 0
length_of_encodings = 0
name_face_encodings = []
names = []




for i in finding_members.list:
findDot = i.find('.')
finding_members.name = i[0:findDot]
if ((len(finding_members.name)) > 1):
names.append(finding_members.name)

print(names)

for i in finding_members.list:

dit = "train_models/"+i
print(dit)
if (i != ".DS_Store"):
images = face_recognition.load_image_file(dit)
findDot = i.find('.')
encoding_name = i[0:findDot]
if (length_of_encodings >= 0):
name_face_encodings.append(face_encoding)





face_encoding = [face_recognition.face_encodings(images)[0]]
length_of_encoding = len(face_encoding)

#face_encoding.update(face_encoding)
print(len(name_face_encodings))

count = count+1
print (count)

while True:
#cv2.imshow('Video', frame)
ret, frame = video_capture.read()
cv2.imshow('video1',frame)
face_locations = face_recognition.face_locations(frame)
face_encodings = face_recognition.face_encodings(frame, face_locations)
#for
for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):
for paru in names:
print(len(name_face_encodings))
print(count1)
local_encoding = name_face_encodings[count1]

match = face_recognition.compare_faces([local_encoding], face_encoding)
count1 = count1 + 1
name = "Unknown"
print(count1)
print(names[count1])
if (match ==True):
name = names[count1]

cv2.rectangle(frame, (left, top), (right, bottom), (100, 40, 100), 2)
font = cv2.FONT_HERSHEY_DUPLEX
cv2.putText(frame, name, (left + 6, top - 6), font, 1.0, (255, 255, 255), 1)

print(names)
#print(len())
cv2.imshow('Video', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break

video_capture.release()
cv2.destroyAllWindows()




finding_members()
print(finding_members.list)
print(finding_members.name)

ValueError: operands could not be broadcast together with shapes (1,0) (128,)

error = match = face_recognition.compare_faces([local_encoding], face_encoding

how to get rid of these error i think comes due to numpy indexing

match = face_recognition.compare_faces([local_encoding], face_encoding)

File "/Users/apple/anaconda3/envs/face_id/lib/python3.6/site-packages/face_recognition/api.py", line 203, in compare_faces

最佳答案

如果我没理解错的话,

video_captured 帧是 BGR,因此帧将其转换为 RGB。

rgb_frame = frame[:, :, ::-1]
face_locations = face_recognition.face_locations(rgb_frame)

关于opencv - 由于 numpy 在 face_recognition 中发生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47487300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com