我在为作业编写的某些代码时遇到麻烦。
我认为mask = source[B-R].point(lambda i: i < -26)
不能分配给函数cv2.dilate(mask, kernel,iterations=1)
我将发布代码的照片
import PIL
from PIL import Image
import numpy as np
import cv2
image = cv2.imread ('/Applications/Python 3.7/Input/1.jpg', 0)
image = Image.open ('/Applications/Python 3.7/Input/1.jpg')
source = image.split()
R, G, B = 0, 1, 2
mask = source[B-R].point(lambda i: i < -26)
kernel = np.ones((9, 9))
mask = cv2.dilate(mask, kernel, iterations=1)
最佳答案
您的面具必须为UMat类型。您的图像是某种PIL图像格式。原始图像是:
print(image.format)
JPEG
并且您的面具是以下类型:
print(mask.format)
None
您也没有使用通过
cv.imread
读取的图像您可以使用opencv创建简单的蒙版,例如像这样的东西:
b,g,r = cv2.split(image)
res = b-r
ret = res[res<26]
mask = cv2.dilate(ret, kernel, iterations=1)
关于python - 为什么会给我TypeError:参数 'src'预期为cv::UMat?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56602659/