서민석
서민석

Reputation: 41

python opencv cv2.threshold( ) , TypeError: Expected cv::UMat for argument 'mat'

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()

The code above works well. However, the code below does not work.

Above cv2.adaptiveThreshold(), below cv2.threshold()

The openvv version is 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()

Traceback (most recent call last): File "down.py", line 26, in cv2.imshow('threshold',tmp3) TypeError: Expected cv::UMat for argument 'mat'

Upvotes: 1

Views: 7200

Answers (1)

Stephen Meschke
Stephen Meschke

Reputation: 2940

threshold() returns a tuple...How Docs Work

Upvotes: 1

Related Questions