V
V
Vartmod2019-03-28 20:27:49
Python
Vartmod, 2019-03-28 20:27:49

How to fix error when changing color space (python 3, OpenCV)?

Hello, dear pythonists) Please tell me, I can’t color the screenshot.
The code is quite simple:

box = (0, 170, 650, 1000)
img = ImageGrab.grab(box)
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

And I get this error: I googled, found this solution:Expected cv::UMat for argument 'src'
gray = cv2.cvtColor(cv2.UMat(img), cv2.COLOR_RGB2GRAY)

But personally, I get the following error: I have no idea what the second argument is, Google too) Somewhere in the bins of overflow I read that the second argument is simply assigned a value . Then the error is as follows: Maybe take a screenshot of the screen through another library? UMat() missing required argument 'ranges' (pos 2)
NoneExpected cv::UMat for argument 'm'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vartmod, 2019-03-28
@Vartmod

I don't know how practical this is, but you can first download the image to disk, and then re-open it with cv2

box = (0, 170, 650, 1000)
img = ImageGrab.grab(box)
img.save("picture.jpg")
image = cv2.imread("picture.jpg")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imwrite("gray.jpg", gray)

It seems that there are no errors)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question