Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
position of the matching
#1
please
I don't understand why this code don't return the x and the y position on the rectangle,
I try to get the position of the matching

import cv2
import pyautogui
import pytesseract
import numpy as np
from PIL import Image

# התחלה : צורת הקלפים
# מציאת עלה בכל חמשת הקלפים הקהילתיים

img = cv2.imread('shot2.png',0)
template = cv2.imread("SS.png",0)
h, w = template.shape
result = cv2.matchTemplate(img, template, cv2.TM_CCOEFF_NORMED)
threshold = 0.95
locations = np.where(result >= threshold)

locations = list(zip(*locations [::-1]))



if locations:



    needle_w = template.shape[1]
    needle_h = template.shape[0]
    line_color = (0, 255, 0)
    line_type = cv2.LINE_4



    # Loop over all the locations and draw their rectangle
    for loc in locations:




        # Determine the box positions
        top_left = loc
        bottom_right = (top_left[0] + needle_w, top_left[1] + needle_h)
        # Draw the box
        cv2.rectangle( img , top_left, bottom_right, line_color, line_type)
        #print(top_left)



    cv2.imshow('Matches', img)
    cv2.waitKey()


else:
    print('S card was not found.')
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020