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
Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130

1 Answers1

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().

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
  • On line 4, I converted that image to numpy array. `img = np.array(img)` –  Jun 07 '16 at 09:25
  • 1
    @rajinikanth convert explicitly to `uint8`. – Miki Jun 07 '16 at 09:29
  • now i got this error: `Traceback (most recent call last): File "E:\python\opencv\template_matching.py", line 14, in img = np.array(img,dtype=np.uint8) TypeError: long() argument must be a string or a number, not 'PixelAccess' ` –  Jun 07 '16 at 09:42