我有一张图片,我想模糊它的一部分。
我正在寻找的输出就像使用PIL, python答案在这个图像的过滤器部分看到的部分模糊的棋盘。
我已经尝试使用上述答案中的代码,但我得到一个错误消息说:
----> 2 ic = image.crop(box)
AttributeError: 'numpy.ndarray' object has no attribute 'crop'
我该如何前进?我应该把np转换成。对图像不感兴趣??
谢谢!
# libraries
import cv2
from PIL import Image
# read in
path = 'C://Users/my_account//Desktop//robert_downey_jr_image.png'
image = cv2.imread(path)
# blurring
box = (30, 30, 110, 110)
ic = image.crop(box)
for i in range(10):
ic = ic.filter(ImageFilter.BLUR)
image.paste(ic, box)
image.show()
# ERROR MESSAGE
----> 2 ic = image.crop(box)
AttributeError: 'numpy.ndarray' object has no attribute 'crop'
您的图像只是一个NumPy数组,它不像您说的那样具有属性裁剪
您需要使用PIL Image库打开它:
image = Image.open(path)
那么你可以调用crop。见https://pillow.readthedocs.io/en/stable/reference/Image.html