import numpy as np
import cv2
imgfile = 'mi.jpg'
img = cv2.imread(imgfile,0)
tmp = img.copy()
kernel_sharpening = np.array([[-1,-1,-1],[-1,9,-1],[-1,-1,-1]])
tmp1 = cv2.pyrDown(tmp) # down sampleing
tmp2 = cv2.GaussianBlur(tmp1,(3,3),0) # bluring
tmp3 =cv2.filter2D(tmp2,-1,kernel_sharpening) # sharping
tmp3 = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY,15,2)
cv2.imshow('threshold',tmp3)
cv2.waitKey()
cv2.destroyAllWindows()
上面的代码运行良好。但是,下面的代码不起作用。
cv2.adaptiveThreshold()之上,cv2.threshold()以下
openvv版本是4。
import numpy as np
import cv2
imgfile = 'mi.jpg'
img = cv2.imread(imgfile,0)
tmp = img.copy()
kernel_sharpening = np.array([[-1,-1,-1],[-1,9,-1],[-1,-1,-1]])
tmp1 = cv2.pyrDown(tmp) # down sampleing
tmp2 = cv2.GaussianBlur(tmp1,(3,3),0) # bluring
tmp3 =cv2.filter2D(tmp2,-1,kernel_sharpening) # sharping
tmp3 = cv2.threshold(tmp3,127,255,cv2.THRESH_BINARY)
cv2.imshow('threshold',tmp3)
cv2.waitKey()
cv2.destroyAllWindows()
回溯(最近一次通话最后一次):文件“ down.py”,第26行,在 cv2.imshow('threshold',tmp3)TypeError:预期的cv :: UMat用于 参数'mat'