I'm trying to write a program that shows a specific position on a given window. When I run the code OpenCV gives me an error message telling me unexpected type for argument mat. I have no idea what's wrong because when I use the position value in the following code it works fine. Please be nice as I'm fairly new to OpenCV.
Code:
#Imports
import numpy as np
import cv2
import pytesseract
from PIL import ImageGrab
import win32gui
#Assign Tesseract and other Variables
winList = []
toplist = []
pytesseract.pytesseract.tesseract_cmd = r'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
lH = 33
lW = 20
#Window Handle Object
def enum_win(hwnd, result):
winText = win32gui.GetWindowText(hwnd)
winList.append((hwnd, winText))
win32gui.EnumWindows(enum_win, toplist)
typeHwnd = 0
#Find Window Handle
for (hwnd, winText) in winList:
if winText == "Program WinText Name Here":
typeHwnd = hwnd
if typeHwnd == 0:
print("Oops no Window Found")
while True:
position = win32gui.GetWindowRect(typeHwnd)
mid = (position[0] + (position[0] + position[2]))/2
sPos = [int(mid)-267, position[1] + 295, lW, lH]
screenshot = ImageGrab.grab(bbox=sPos)
screenshot = np.array(screenshot)
cv2.imshow("Screen", screenshot)
key = cv2.waitKey(25)
print(position)
print(mid)
Error Message:
Traceback (most recent call last):
File "C:/Users/MyName/PycharmProjects/Typing Bot/main.py", line 47, in <module>
cv2.imshow("Screen", screenshot)
TypeError: Expected Ptr<cv::UMat> for argument 'mat'
System Specifications:
I am running Windows 10 64 bit and Python 3 with the most recent version of all the imported modules installed.