I am trying to use homography for court detection. And I have detected an object (a player) in the original image and I am now trying to figure out what are it's new coordinates on the wrapped image.
(I am trying to create a minimap system)
I want to figure out new x and y coordinates of the player on the wrapped image
This is my program so far:
import cv2
import numpy as np
import matplotlib.pyplot as plt
#player coordinates - multiple players
x_coords = []
y_coords = []
print(x_coords)
print(y_coords)
#basketball court, size-1830, 910
pts_src = np.array([
[394, 412], # top left corner
[0, 500],
[0, 670],
[910, 770],
[1830, 720],
[1830,545],
[1540, 450] # top right corner
])
#minimap, size-500,300
pts_dst = np.array([
[0, 0], # top left corner
[0, 275],
[25, 300],
[250, 300],
[475, 300],
[500, 275],
[500, 0] # top right corner
])
#find homography
h, status = cv2.findHomography(pts_src, pts_dst)
img_src2 = cv2.imread('basketball_court.png')
img_out = cv2.warpPerspective(img_src2, h, (img_dst.shape[1], img_dst.shape[0]))
cv2.imshow("Warped", img_out)
cv2.waitKey(0)`
I have tried using this for help but just can't figure out what to do: Opencv homography to find global xy coordinates from pixel xy coordinates