Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用image.crop()模糊图像-AttributeError:';numpy.ndarray和#x27;对象没有属性';作物';_Python_Image_Image Processing_Computer Vision_Python Imaging Library - Fatal编程技术网

Python 使用image.crop()模糊图像-AttributeError:';numpy.ndarray和#x27;对象没有属性';作物';

Python 使用image.crop()模糊图像-AttributeError:';numpy.ndarray和#x27;对象没有属性';作物';,python,image,image-processing,computer-vision,python-imaging-library,Python,Image,Image Processing,Computer Vision,Python Imaging Library,我有一个图像,我想模糊它的一部分 我要寻找的输出就像这个答案中看到的部分模糊的棋盘 我已尝试使用上述答案中的代码,但我收到一条错误消息,上面说: --->2 ic=image.crop(框) AttributeError:'numpy.ndarray'对象没有属性“crop” 我该如何前进?我是否应该尝试将np.ndarry转换为图像 谢谢 # libraries import cv2 from PIL import Image # read in path = 'C://Users/m

我有一个图像,我想模糊它的一部分

我要寻找的输出就像这个答案中看到的部分模糊的棋盘

我已尝试使用上述答案中的代码,但我收到一条错误消息,上面说:

--->2 ic=image.crop(框)

AttributeError:'numpy.ndarray'对象没有属性“crop”

我该如何前进?我是否应该尝试将np.ndarry转换为图像

谢谢

# 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数组,它没有您所说的属性crop

您需要通过以下方式使用PIL图像库打开它:

image = Image.open(path)
然后你可以打电话给crop。看