Reputation:
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
Upvotes: 1
Views: 859
Reputation: 22744
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()
.
Upvotes: 1