user11297709
user11297709

Reputation:

Why is it giving me TypeError: Expected cv::UMat for argument 'src'?

I am finding trouble with some code that I am writing for homework. I think that mask = source[B-R].point(lambda i: i < -26) can't be assigned to the function cv2.dilate(mask, kernel,iterations=1) I will post the photo of the code

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)

Upvotes: 0

Views: 9391

Answers (1)

Julian
Julian

Reputation: 989

Your masks needs to be of type UMat. Your image is some kind of PIL Image format. The original image is:

print(image.format)
JPEG

and your mask is of type:

print(mask.format)
None

You are also not using the image you read with cv.imread

You can create a simple mask using opencv e.g. something like this:

b,g,r = cv2.split(image)
res = b-r
ret = res[res<26]
mask = cv2.dilate(ret, kernel, iterations=1)

Upvotes: 2

Related Questions