Python openCV模糊图像

Python openCV模糊图像,python,python-3.x,Python,Python 3.x,获取以下消息:TypeError:参数“%s”应为Ptr 我不知道为什么它不起作用。有什么想法吗 # Load picture as a numpy array import cv2 image = cv2 . imread ("beatles.jpg") image = cv2 . cvtColor ( image , cv2 . COLOR_BGR2RGB ) # See that it is working print (image) cv2.imshow("Bilde", image

获取以下消息:
TypeError:参数“%s”应为Ptr

我不知道为什么它不起作用。有什么想法吗

# Load picture as a numpy array
import cv2
image = cv2 . imread ("beatles.jpg")
image = cv2 . cvtColor ( image , cv2 . COLOR_BGR2RGB )

# See that it is working 
print (image)
cv2.imshow("Bilde", image)
cv2.waitKey (5000)
cv2.destroyAllWindows() 

# Box Blur kernel
box_kernel = [[1 / 9, 1 / 9, 1 / 9], [1 / 9, 1 / 9, 1 / 9], [1 / 9, 1 / 9, 1 / 9]]
kernel = box_kernel

cv2.filter2D(image, -1, kernel)
TypeError:参数“%s”应为Ptr
尝试使用

import numpy as np
box_kernel = np.array([[1 / 9, 1 / 9, 1 / 9], [1 / 9, 1 / 9, 1 / 9], [1 / 9, 1 / 9, 1 / 9]])

,似乎您必须以numpy
ndarray
的形式提供内核。我怀疑这与OpenCV是用C/C++编写的事实有关,在C/C++中,参数通过引用或指针而不是通过值传递到
filter2D
。在Python中,没有办法通过
列表来实现这一点,但是numpy的
ndarray
在后台使用C,OpenCV的Python接口可能有办法将其传递到C/C++代码中。

发布完整的堆栈跟踪,这将提高您获得答案的机会
import numpy as np
box_kernel = np.array([[1 / 9, 1 / 9, 1 / 9], [1 / 9, 1 / 9, 1 / 9], [1 / 9, 1 / 9, 1 / 9]])