如何解决通过HOG算法执行人脸识别时,名称重复两次
在通过HOG算法执行面部识别时,名称重复两次。这是我的代码:
import face_recognition
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle
from matplotlib.patches import Circle
import numpy as np
import cv2
%matplotlib inline
# Load each person's single image
img2 = cv2.imread('/content/gdrive/My Drive/piyush-chawla.jpg')
pw = cv2.cvtColor(img2,cv2.COLOR_BGR2RGB)
img3 = cv2.imread('/content/gdrive/My Drive/sreesanth.jpg')
sree = cv2.cvtColor(img3,cv2.COLOR_BGR2RGB)
img4 = cv2.imread('/content/gdrive/My Drive/suresh-raina.jpg')
sura = cv2.cvtColor(img4,cv2.COLOR_BGR2RGB)
img5 = cv2.imread('/content/gdrive/My Drive/virender-sehwag.jpg')
vs = cv2.cvtColor(img5,cv2.COLOR_BGR2RGB)
img6 = cv2.imread('/content/gdrive/My Drive/harbhajan-singh.jpg')
hs = cv2.cvtColor(img6,cv2.COLOR_BGR2RGB)
img7 = cv2.imread('/content/gdrive/My Drive/gautam-gambhir.jpg')
gg = cv2.cvtColor(img7,cv2.COLOR_BGR2RGB)
# Get the Face encoding of each person. This can fail if no one is found in the photo
pw_encoding = face_recognition.face_encodings(pw)[0]
sree_encoding = face_recognition.face_encodings(sree)[0]
sura_encoding = face_recognition.face_encodings(sura)[0]
vs_encoding = face_recognition.face_encodings(vs)[0]
hs_encoding = face_recognition.face_encodings(hs)[0]
gg_encoding = face_recognition.face_encodings(gg)[0]
img_encoding = face_recognition.face_encodings(img)[0]
# Create a Database of all known face encodings
known = [
pw_encoding,sree_encoding,sura_encoding,vs_encoding,hs_encoding,gg_encoding,img_encoding
]
# Loading the image we want to check for multiple faces to recognize
unk = cv2.imread('/content/gdrive/My Drive/india-wins-world-cup-2011.jpg')
unk = cv2.cvtColor(unk,cv2.COLOR_BGR2RGB)
plt.figure(figsize = (20,10))
plt.imshow(unk)
# Get face encodings of the unknown image
unk_encoding = face_recognition.face_encodings(unk)
from scipy.spatial import distance
# There might be more than one person in the unknown photo,so we need to loop over each face we found
for k in unk_encoding:
# Compute Euclidean distance
results = []
for l in known:
d = distance.euclidean(l,k)
results.append(d)
threshold = 0.6
results = np.array(results) <= threshold
name = "Unknown"
if results[0]:
name = "Gautam Gambhir"
elif results[1]:
name = "Sreesanth"
elif results[2]:
name = "Sachin Tendulkar"
elif results[3]:
name = "Harbhajan Singh"
elif results[4]:
name = "Suresh Raina"
elif results[5]:
name = "Piyush Chawla"
elif results[6]:
name = "Virender Sehwag"
print(f"Found {name} in the photo")
输出如下:
Found Virender Sehwag in the photo
Found Gautam Gambhir in the photo
Found Harbhajan Singh in the photo
Found Sachin Tendulkar in the photo
Found Gautam Gambhir in the photo
Found Piyush Chawla in the photo
Found Sreesanth in the photo
即使我更改了索引,也无法获得原始图像中出现的所有7位球员的名字,这些名字的面孔-Sachin Tendulkar,Gautam Gambhir,Piyush Chawla,Suresh Raina,Sreesanth,Virender Sehwag和Harbhajan Singh 。 在此,一个名字被重复两次,由于错过了一个玩家名字。 该怎么办?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。