python:MTCNN没有保存所有文件
sap人员!我在编写这段代码时遇到了一些问题,这里的要点是我想用MTCNN lib裁剪一些图片的面,然后在运行这段代码时将其保存为.jpg文件:python:MTCNN没有保存所有文件,python,deep-learning,computer-vision,Python,Deep Learning,Computer Vision,sap人员!我在编写这段代码时遇到了一些问题,这里的要点是我想用MTCNN lib裁剪一些图片的面,然后在运行这段代码时将其保存为.jpg文件: # draw each face separately def draw_faces(filename, result_list): # load the image data = pyplot.imread(filename) # plot each face as a subplot
# draw each face separately
def draw_faces(filename, result_list):
# load the image
data = pyplot.imread(filename)
# plot each face as a subplot
for i in range(len(result_list)):
# get coordinates
x1, y1, width, height = result_list[i]['box']
x2, y2 = x1 + width, y1 + height
# define subplot
pyplot.subplot(1, len(result_list), i+1)
pyplot.axis('off')
# plot face
pyplot.imshow(data[y1:y2, x1:x2])
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
pyplot.imwrite(justfaces+name+'/'+file, )
# show the plot
pyplot.show()
for name in names:
onlyfiles = [ f for f in listdir(os.path.join(ALL_DATA,name)) ]
os.mkdir(os.path.join(justfaces,name))
for file in onlyfiles:
filename = '%s/%s' % (ALL_DATA+name, file)
# load image from file
pixels = pyplot.imread(filename)
# create the detector, using default weights
detector = MTCNN()
#detect faces in the image
faces = detector.detect_faces(pixels)
print(faces)
# display faces on the original image
draw_faces(filename, faces)
代码正常工作,但在某种程度上我遇到了这个错误
ValueError: zero-size array to reduction operation minimum which has no identity
现在的问题是,我认为有一张没有人的照片,所以没有脸可以写,一些for loop出现了这个错误,如果你们能帮助我,我将非常感激,提前感谢你们阅读
编辑:
我正在查看draw_face返回的json,就在它提示错误之前,它看起来像这样
[{'box': [170, -22, 177, 242], 'confidence': 0.9992941617965698, 'keypoints': {'left_eye': (227, 62), 'right_eye': (305, 73), 'nose': (257, 110), 'mouth_left': (220, 151), 'mouth_right': (288, 162)}}]
有趣的是框的第二个条目中的-22,这可能是错误的原因吗?如果是这样的话,你知道如何阻止它吗 就我所知,这个问题的解决方案是: mtncc被窃听了,正如github问题()所声称的()有时它得到的坐标是负数,所以我决定做一些更改,实际上只要把x和y=0,如果它们是负数,现在这就解决了我的问题,这里的代码是=3
#cropeo de caras y creacion de nueva carpeta para solo caras
names = [l for l in listdir(TOP_DATA) if os.path.isdir(join(TOP_DATA,l)) ]
# draw each face separately
def draw_faces(filename, result_list):
# load the image
data = pyplot.imread(filename)
# plot each face as a subplot
k = 1
for i in range(len(result_list)):
# get coordinates
x1, y1, width, height = result_list[i]['box']
x2, y2 = x1 + width, y1 + height
if x1 <0:
x1=0
if x2 <0:
x2=0
if y1 <0:
y1=0
if y2 <0:
y2=0
# save face
lalala = cvtColor(data[y1:y2, x1:x2], COLOR_RGB2BGR)
outfile = '%s/%s_%s' % (FACES+name, k, file)
imwrite(outfile,lalala)
k +=k
for name in names:
onlyfiles = [ f for f in listdir(os.path.join(TOP_DATA,name)) ]
os.mkdir(os.path.join(FACES,name))
for file in onlyfiles:
filename = '%s/%s' % (TOP_DATA+name, file)
# load image from file
pixels = pyplot.imread(filename)
# create the detector, using default weights
detector = MTCNN()
#detect faces in the image
faces = detector.detect_faces(pixels)
# display faces on the original image
draw_faces(filename, faces)
#cropeo de caras和creacion de nueva地毯
names=[l代表listdir(TOP_数据)中的l,如果os.path.isdir(join(TOP_数据,l))]
#分别绘制每个面
def绘图面(文件名、结果列表):
#加载图像
data=pyplot.imread(文件名)
#将每个面绘制为子图
k=1
对于范围内的i(len(结果列表)):
#获取坐标
x1,y1,宽度,高度=结果_列表[i]['box']
x2,y2=x1+宽度,y1+高度
如果x1