python opencv cv2.threshold(),TypeError:参数'mat'的预期cv :: UMat

时间:2019-03-12 15:21:58

标签: python opencv

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'

0 个答案:

没有答案