I need someone to explain to me these four lines of code:
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
threshhold = 0.70
loc = np.where( res >= threshhold)
for pt in zip(*loc[:: -1]):
I kind of know what the first two mean. But the loop part drives me crazy.
- What zip() does in this situation?
- Why did we reverse the list
- what does "*loc" mean? I mean the asteriks
- Whats pt at all?
Rest of the code (the part that matters):
while True:
for i in range(4):
img_gray = cv2.cvtColor(imageGrab(), cv2.COLOR_BGR2GRAY)
f = str(files[i])
template = cv2.imread(f, 0)
w, h = template.shape[:: -1]
res = cv2.matchTemplate(img_gray, template, cv2.TM_CCOEFF_NORMED)
threshhold = 0.70
loc = np.where( res >= threshhold)
for pt in zip(*loc[:: -1]):
x=pt[0]
y=pt[1]
center_x = (x + 0.5 * w) + 415
center_y = (y + 0.5 * h) + 287
pyautogui.click(center_x , center_y)
time.sleep(4)
count = count + 1
break
I put the break at the end because I only want to use the loop once (Do you think there is any better way to do this?)
I will be very thankfull for all the people that answer. You dont have to answer all my questions, if you only know an answer to one then share. Thanks <3