'How do I Debug This Traceback Error in Python?
import cv2
import numpy as np
import mss
from win32api import GetSystemMetrics
sct = mss.mss()
dimensions_full = {
'left': 0,
'top': 0,
'width': GetSystemMetrics(0),
'height': GetSystemMetrics(1)
}
fullscreen_img = np.array(sct.grab(dimensions_full))
game_img = cv2.imread('capture.JPG', cv2.IMREAD_UNCHANGED)
spell_money_img = cv2.imread('spell_money.JPG', cv2.IMREAD_UNCHANGED)
result = cv2.matchTemplate(fullscreen_img, spell_money_img, cv2.TM_CCOEFF_NORMED)
When I run this code I get a
---------------------------------------------------------------------------
error Traceback (most recent call last)
c:\Users\InvestorSauce\Documents\Programming\PythonCVBot\bot.ipynb Cell 5' in <cell line: 1>()
----> 1 result = cv2.matchTemplate(fullscreen_img, spell_money_img, cv2.TM_CCOEFF_NORMED)
error: OpenCV(4.5.5) D:\a\opencv-python\opencv-python\opencv\modules\imgproc\src\templmatch.cpp:1164: error: (-215:Assertion failed) (depth == CV_8U || depth == CV_32F) && type == _templ.type() && _img.dims() <= 2 in function 'cv::matchTemplate'
Im new to python and dont understand what the issue is. If I run the code trying to compare the game_img with spell_money_img it works, but not when im taking a screenshot first. I assume im passing the wrong variable in as in game_img and spell_money_img are different variables? Thanks
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
