1

Part of my code is :

import pyscreenshot as ImageGrab
img=ImageGrab.grab()
img = img.load()
img = np.array(img)
template = cv2.imread('s2_5.jpg',0)
res = cv2.matchTemplate(img,template,cv2.TM_CCOEFF)

I'm getting the following error message:

Traceback (most recent call last):  
  File "E:\python\opencv\template_matching.py", line 20, in <module>
  res = cv2.matchTemplate(img,template,cv2.TM_CCOEFF)
TypeError: image data type = 17 is not supported

1 Answer 1

1

You get that error because img and template are not of the same type, and more importantly, as the error messages says, img's type is not supported by cv2.matchTemplate().

On line 20 of your code, ImageGrab.grab() returns a PIL/Pillow image. So you need to convert img to a numpy array before using it as an input of cv2.matchTemplate().

Sign up to request clarification or add additional context in comments.

3 Comments

On line 4, I converted that image to numpy array. img = np.array(img)
@rajinikanth convert explicitly to uint8.
now i got this error: Traceback (most recent call last): File "E:\python\opencv\template_matching.py", line 14, in <module> img = np.array(img,dtype=np.uint8) TypeError: long() argument must be a string or a number, not 'PixelAccess'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.