面部编码的形状不同
Shape of face encodings differ
我正在尝试制作人脸识别程序,但问题是某些编码的人脸编码形状比其他编码大,因此我收到错误
ValueError: setting an array element with a sequence.
这是我生成编码的代码
class FaceEncoder():
def __init__(self, files, singleton = False, model_path='./models/lbpcascade_animeface.xml', scale_factor=1.1, min_neighbours=1):
self.singleton = singleton
self.files = files
self.model = model_path
self.scale_factor = scale_factor
self.min_neighbours = min_neighbours
def encode(self, singleton=False):
if self.singleton == False:
encodings = []
labels = []
for file in self.files:
cascade = cv2.CascadeClassifier(self.model)
image = cv2.imread(file)
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
faces = cascade.detectMultiScale(rgb, self.scale_factor, self.min_neighbours)
if len(faces) > 0:
print('Found face in '+file)
encodings.append(faces.flatten())
labels.append(file.split('/')[2])
else:
print('Couldnt find face in '+file)
return encodings, labels
这里是一些编码
[204 96 211 211]
[525 168 680 680]
[205 11 269 269]
[ 165 31 316 316 1098 181 179 179]
[ 113 422 1371 1371]
[ 71 86 183 183]
[209 19 33 33 88 27 60 60 133 80 65 65 68 117 52 52]
[117 77 149 149]
[ 63 77 284 284]
[370 222 490 490]
[433 112 114 114 183 98 358 358]
[ 44 35 48 48 192 34 48 48]
[210 82 229 229]
[429 90 153 153]
[318 50 174 174 118 142 120 120]
您不应将找到的多个矩形放入同一个列表条目中。
如果找到很多面孔,将每个面孔放在自己的行中,并为找到的每个面孔添加一个标签(而不是每个图像)
那么,您现在拥有的不是“编码”,只是方框/矩形。
阅读如何获得真正的编码(facenet、spherenet?),然后您需要:
- 裁剪图像中的面部区域
- 将其调整为 nn 个输入大小(例如 96x96)
- 运行它通过nn来接收编码
- 将 that 连同标签保存到 db/list
我正在尝试制作人脸识别程序,但问题是某些编码的人脸编码形状比其他编码大,因此我收到错误
ValueError: setting an array element with a sequence.
这是我生成编码的代码
class FaceEncoder():
def __init__(self, files, singleton = False, model_path='./models/lbpcascade_animeface.xml', scale_factor=1.1, min_neighbours=1):
self.singleton = singleton
self.files = files
self.model = model_path
self.scale_factor = scale_factor
self.min_neighbours = min_neighbours
def encode(self, singleton=False):
if self.singleton == False:
encodings = []
labels = []
for file in self.files:
cascade = cv2.CascadeClassifier(self.model)
image = cv2.imread(file)
rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
faces = cascade.detectMultiScale(rgb, self.scale_factor, self.min_neighbours)
if len(faces) > 0:
print('Found face in '+file)
encodings.append(faces.flatten())
labels.append(file.split('/')[2])
else:
print('Couldnt find face in '+file)
return encodings, labels
这里是一些编码
[204 96 211 211]
[525 168 680 680]
[205 11 269 269]
[ 165 31 316 316 1098 181 179 179]
[ 113 422 1371 1371]
[ 71 86 183 183]
[209 19 33 33 88 27 60 60 133 80 65 65 68 117 52 52]
[117 77 149 149]
[ 63 77 284 284]
[370 222 490 490]
[433 112 114 114 183 98 358 358]
[ 44 35 48 48 192 34 48 48]
[210 82 229 229]
[429 90 153 153]
[318 50 174 174 118 142 120 120]
您不应将找到的多个矩形放入同一个列表条目中。 如果找到很多面孔,将每个面孔放在自己的行中,并为找到的每个面孔添加一个标签(而不是每个图像)
那么,您现在拥有的不是“编码”,只是方框/矩形。
阅读如何获得真正的编码(facenet、spherenet?),然后您需要:
- 裁剪图像中的面部区域
- 将其调整为 nn 个输入大小(例如 96x96)
- 运行它通过nn来接收编码
- 将 that 连同标签保存到 db/list