Updated by Andrey Kamaev about 13 years ago
For small kernel sizes, the Python cv2-wrapper for filter2D works fine:
<pre><code class="python"> <pre>
import numpy as np
import cv2
# Generate a homogenous image
img = np.uint8(np.ones((750,1000)))
# For a medium size kernel, the "filter2D" works
filterSize = 11
myFilter = np.ones((filterSize, filterSize))/filterSize**2
imFiltered = cv2.filter2D(img, -1, myFilter)
print 'ok'
</code></pre> </pre>
However, when the kernel gets any larger, "filter2D" crashes:
<pre><code class="python"> <pre>
# But for a larger kernel, it breaks
filterSize = 13
myFilter = np.ones((filterSize, filterSize))/filterSize**2
imFiltered = cv2.filter2D(img, -1, myFilter)
</code></pre> </pre>
with the error message
<pre>
OpenCV [[OpenCV]] Error: Assertion failed (depth == tdepth || tdepth == CV_32F) in unknown function, file ..\..\..\OpenCV-2.3.1\modules\imgproc\src\templmatch.cpp, line 61
Traceback (most recent call last):
File "C:\Users\p20529\Coding\Python\Dev\openCV\problem.py", line 18, in <module>
imFiltered = cv2.filter2D(img, -1, myFilter)
cv2.error: ..\..\..\OpenCV-2.3.1\modules\imgproc\src\templmatch.cpp:61: error: (-215) depth == tdepth || tdepth == CV_32F
</pre>
<pre><code class="python"> <pre>
import numpy as np
import cv2
# Generate a homogenous image
img = np.uint8(np.ones((750,1000)))
# For a medium size kernel, the "filter2D" works
filterSize = 11
myFilter = np.ones((filterSize, filterSize))/filterSize**2
imFiltered = cv2.filter2D(img, -1, myFilter)
print 'ok'
</code></pre> </pre>
However, when the kernel gets any larger, "filter2D" crashes:
<pre><code class="python"> <pre>
# But for a larger kernel, it breaks
filterSize = 13
myFilter = np.ones((filterSize, filterSize))/filterSize**2
imFiltered = cv2.filter2D(img, -1, myFilter)
</code></pre> </pre>
with the error message
<pre>
OpenCV [[OpenCV]] Error: Assertion failed (depth == tdepth || tdepth == CV_32F) in unknown function, file ..\..\..\OpenCV-2.3.1\modules\imgproc\src\templmatch.cpp, line 61
Traceback (most recent call last):
File "C:\Users\p20529\Coding\Python\Dev\openCV\problem.py", line 18, in <module>
imFiltered = cv2.filter2D(img, -1, myFilter)
cv2.error: ..\..\..\OpenCV-2.3.1\modules\imgproc\src\templmatch.cpp:61: error: (-215) depth == tdepth || tdepth == CV_32F
</pre>