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

Hello, dear pythonista) please Tell me, can't paint the screen
The code is rather simple:
box = (0, 170, 650, 1000)
img = ImageGrab.grab(box)
imgGray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

And it turns out this error: Expected cv::UMat for argument 'src'

Googled, found this solution:
gray = cv2.cvtColor(cv2.UMat(img), cv2.COLOR_RGB2GRAY)

But personally, I have the following error message: UMat() missing required argument 'ranges' (pos 2)

Have no idea what the second argument, Google is also) somewhere in the bins overflow I read that the second argument is simply assign the value None. Then, the error is:Expected cv::UMat for argument 'm'

Maybe a screenshot of the screen to be done through another library?
March 19th 20 at 09:04
2 answers
March 19th 20 at 09:06
Don't know how practical, but you can first upload the image to disk, and then re-open it using cv2
box = (0, 170, 650, 1000)
img = ImageGrab.grab(box)"picture.jpg")
image = cv2.imread("picture.jpg")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imwrite("gray.jpg", gray)

Seems to be no errors)
March 19th 20 at 09:08
You need Preobrazovatel image to a numpy array, you can use the following code
img = numpy.asarray( img, dtype="int32" )

Find more questions by tags OpenCVPython