gpt4 book ai didi

python opencv cv2.threshold( ) ,类型错误:参数 'mat' 的预期 cv::UMat

转载 作者:太空宇宙 更新时间:2023-11-03 22:39:47 28 4
gpt4 key购买 nike

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

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

最佳答案

threshold() 返回一个元组... How Docs Work

关于python opencv cv2.threshold( ) ,类型错误:参数 'mat' 的预期 cv::UMat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55125055/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com