【发布时间】:2021-07-20 21:38:12
【问题描述】:
我有这段代码,其中 mtcnn 检测图像上的人脸,在每个人脸周围绘制一个红色矩形并在屏幕上打印。
但我想保存每张脸周围有红色框的图像。这样我就可以对其进行一些预处理。任何帮助都是好的。
# draw an image with detected objects
def draw_image_with_boxes(filename, result_list):
# load the image
data = pyplot.imread(filename)
# plot the image
pyplot.imshow(data)
# get the context for drawing boxes
ax = pyplot.gca()
# plot each box
for result in result_list:
# get coordinates
x, y, width, height = result['box']
# create the shape
rect = Rectangle((x, y), width, height, fill=False, color='red')
# draw the box
ax.add_patch(rect)
# show the plot
pyplot.show()
filename = 'test1.jpg'
# 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_image_with_boxes(filename, faces)
【问题讨论】:
标签: image matplotlib image-processing face-detection