python打开图片的几种方法

python打开图片的几种方法,第1张

1. opencv方法
import cv2
img_path =r"C:/Users/gf879/Pictures/Saved Pictures/cat1.jpg"
img = cv2.imread(img_path)
cv2.namedWindow('myPicture',0)
cv2.resizeWindow('myPicture', 500, 500)
cv2.imshow('myPicture',img)
cv2.waitKey()
cv2.destroyWindow('myPicture')

结果:

 

2. matplotlib方法
import matplotlib.pyplot as plt
img_path =r"C:/Users/gf879/Pictures/Saved Pictures/cat1.jpg"
img = plt.imread(img_path)
fig = plt.figure('show picture')
# ax = fig.add_subplot(111)
plt.imshow(img)
plt.show()

结果:

3. PIL
from PIL import Image
img=Image.open('C:/Users/gf879/Pictures/Saved Pictures/cat1.jpg')
img.show()

结果:

 

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/795197.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-06
下一篇 2022-05-06

发表评论

登录后才能评论

评论列表(0条)

保存