import matplotlib.pyplot as plt
import cv2
im = cv2.imread("1.jpg")
im = cv2.resize(im, (400, 400))
fig, ax = plt.subplots()
im = im[:, :, (2, 1, 0)]
ax.imshow(im, aspect="equal")
plt.axis("off")
# 去除图像周围的白边
height, width, channels = im.shape
# 如果dpi=300,那么图像大小=height*width
fig.set_size_inches(width / 100.0, height / 100.0)
plt.gca().xaxis.set_major_locator(plt.NullLocator())
plt.gca().yaxis.set_major_locator(plt.NullLocator())
plt.subplots_adjust(top=1, bottom=0, left=0, right=1, hspace=0, wspace=0)
plt.margins(0, 0)
plt.savefig("result.png")
image.png
image.png
网友评论