You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
hey there, I'm having difficulty figuring out how to get my template to match the game recording for my code. This is the test code that I'm trying to run, and it just doesn't seem to work. I do realize I haven't run the exact code that you put on your videos, but that is because I can't seem to get it to window/video capture for the game I'm playing, (which is a little frustrating).
Nevertheless, it works for still image and it works fine videocapturing when I don't try to matchTemplate but the two don't seem to want to merge.
import numpy as np
from PIL import ImageGrab
import cv2
import time
import threading
def screen_record():
last_time = time.time()
while(True):
# 800x600 windowed mode for GTA 5, at the top left position of your main screen.
# 40 px accounts for title bar.
printscreen = np.array(ImageGrab.grab(bbox=(0,40,800,640)))
print('loop took {} seconds'.format(time.time()-last_time))
last_time = time.time()
img_gray = cv2.imshow('window',cv2.cvtColor(printscreen, cv2.COLOR_BGR2GRAY))
if cv2.waitKey(25) & 0xFF == ord('q'):
cv2.destroyAllWindows()
break
eyes_hungry = cv2.imshow('hungry2.jpg',0)
last_time = time.time()
res = cv2.matchTemplate(img_gray, eyes_hungry, cv2.TM_CCOEFF_NORMED)
threshhold = 0.8
loc = np.where(res >= threshhold)
for pt in zip(*loc[::-1]):
w, h = template.shape[::-1]
cv2.rectangle(img_gray, pt, (pt[0]+w, pt[1]+h), (0,255,255), 1)
screen_record()
this is the error or a variation on the same error I get when I try running it:
F:\Desktop\Ne\neat-python>grabscreen.py
loop took 0.0657804012298584 seconds
Traceback (most recent call last):
File "F:\Desktop\Ne\neat-python\grabscreen.py", line 29, in <module>
screen_record()
File "F:\Desktop\Ne\neat-python\grabscreen.py", line 22, in screen_record
res = cv2.matchTemplate(img_gray, eyes_hungry, cv2.TM_CCOEFF_NORMED)
cv2.error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-sn_xpupm\opencv\modules\imgproc\src\templmatch.cpp:588: error: (-215:Assertion failed) corr.rows <= img.rows + templ.rows - 1 && corr.cols <= img.cols + templ.cols - 1 in function 'cv::crossCorr'
if you or anyone might be able to help, I'd really appreciate it, I've been banging my head on the wall for a few days now.
Thank you for reading.
The text was updated successfully, but these errors were encountered:
hey there, I'm having difficulty figuring out how to get my template to match the game recording for my code. This is the test code that I'm trying to run, and it just doesn't seem to work. I do realize I haven't run the exact code that you put on your videos, but that is because I can't seem to get it to window/video capture for the game I'm playing, (which is a little frustrating).
Nevertheless, it works for still image and it works fine videocapturing when I don't try to matchTemplate but the two don't seem to want to merge.
this is the error or a variation on the same error I get when I try running it:
if you or anyone might be able to help, I'd really appreciate it, I've been banging my head on the wall for a few days now.
Thank you for reading.
The text was updated successfully, but these errors were encountered: