【问题标题】:How to save the image with the red bounding boxes on it detected by mtcnn?如何保存 mtcnn 检测到的带有红色边界框的图像?
【发布时间】:2021-07-20 21:38:12
【问题描述】:

我有这段代码,其中 mtcnn 检测图像上的人脸,在每个人脸周围绘制一个红色矩形并在屏幕上打印。

代码取自:https://machinelearningmastery.com/how-to-perform-face-detection-with-classical-and-deep-learning-methods-in-python-with-keras/

但我想保存每张脸周围有红色框的图像。这样我就可以对其进行一些预处理。任何帮助都是好的。

# 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)

This image so that i can display it on an html

【问题讨论】:

    标签: image matplotlib image-processing face-detection


    【解决方案1】:

    您可以使用matplotlib.pyplot.savefig。例如:

    # save the plot
    plt.savefig('image_with_box.jpg')
    # show the plot
    pyplot.show()
    

    您可以在此处找到更多详细信息:https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-19
      • 1970-01-01
      • 1970-01-01
      • 2011-09-11
      • 2016-10-03
      • 1970-01-01
      • 2011-11-12
      • 1970-01-01
      相关资源
      最近更新 更多