Created
May 30, 2022 23:49
-
-
Save arhanjain/2fbebda639388eaddaf5746af50edc3c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def warp_frame(frame, playfield_corners): | |
""" | |
Warps the frame to the playfield. | |
Parameters | |
---------- | |
frame : np.ndarray | |
The frame to transform. | |
playfield_corners : list | |
The coordinates of the corners of the playfield. | |
Returns | |
------- | |
np.ndarray | |
The warped frame. | |
""" | |
playfield_corners_sorted = PinballUtils.sort_coordinates(playfield_corners) | |
display_corners_sorted = PinballUtils.sort_coordinates([ | |
[0, 0], | |
[frame.shape[1], 0], | |
[frame.shape[1], frame.shape[0]], | |
[0, frame.shape[0]] | |
]) | |
# Calculate transformation matrix | |
transformation_matrix = cv2.getPerspectiveTransform(playfield_corners_sorted, display_corners_sorted) | |
return cv2.warpPerspective(frame, transformation_matrix, (frame.shape[1], frame.shape[0])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment