I have tried to execute the following code
import numpy as np
import cv2
g_kernel = cv2.getGaborKernel((21, 21), 8.0, np.pi/4, 10.0, 0.5, 0, ktype=cv2.CV_32F)
img = cv2.imread('H:\PyCharm WorkSpace\images\image-0.png')
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
filtered_img = cv2.filter2D(img, cv2.CV_8UC3, g_kernel)
cv2.imshow('image', img)
cv2.imshow('filtered image', filtered_img)
h, w = g_kernel.shape[:2]
g_kernel = cv2.resize(g_kernel, (3*w, 3*h), interpolation=cv2.INTER_CUBIC)
cv2.imshow('gabor kernel (resized)', g_kernel)
cv2.waitKey(0)
cv2.destroyAllWindows()
After running this code, it gives the following error:
Traceback (most recent call last):
File "H:/PyCharm WorkSpace/opencv.py", line 24, in <module>
cv2.imshow('gabor kernel (resized)', g_kernel)
cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\highgui\src\window_w32.cpp:1230: error:
(-215:Assertion failed) dst.data == (uchar*)dst_ptr in function
'cvShowImage'
Can anyone please tell me what is the mistake?
You are trying to resize g_kernel which is a kernel. cv2.resize needs an image to be resized. If you want to resize the filtered_img then change the following line in your code:
g_kernel = cv2.resize(g_kernel, (3*w, 3*h), interpolation=cv2.INTER_CUBIC)
to:
g_kernel = cv2.resize(filtered_img, (3*w, 3*h), interpolation=cv2.INTER_CUBIC)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.