通过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 。 在此,一个名字被重复两次,由于错过了一个玩家名字。 该怎么办?

具有多张面孔的图像的链接为https://www.google.co.in/url?sa=i&url=https%3A%2F%2Fcricketaddictor.com%2Fcricket%2F3-heroes-india-2011-world-cup-triumph%2F&psig=AOvVaw3KcH7gpfRIDx2I4skIRJof&ust=1597508945878000&source=images&cd=vfe&ved=0CAIQjRxqFwoTCODrpvqOm-sCFQAAAAAdAAAAABAE

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...