Skip to content

Instantly share code, notes, and snippets.

@RodrigoCMoraes
Created February 4, 2019 18:21
Show Gist options
  • Save RodrigoCMoraes/d1254ab466b5b3a817f32b6bbe5e1100 to your computer and use it in GitHub Desktop.
Save RodrigoCMoraes/d1254ab466b5b3a817f32b6bbe5e1100 to your computer and use it in GitHub Desktop.
import cv2
import numpy as np
screen_width, screen_height = 1920, 1080
window_width, window_height = 1270, 720
path = "template.jpeg"
image = cv2.imread(path)
image_width, image_height = image.shape[:2]
window_name = "Manual Perspective Correction"
cv2.namedWindow(window_name, cv2.WINDOW_NORMAL)
cv2.resizeWindow(window_name, window_width, window_height)
cv2.moveWindow(window_name, screen_width//2 - window_width//2, screen_height//2 - window_height//2)
pts_src = np.float32([[120, 215], [650, 205], [138, 910], [695, 860]])
pts_dst = np.float32([[0, 0], [972, 0], [0, 729], [972, 729]])
M = cv2.getPerspectiveTransform(pts_src, pts_dst)
dst = cv2.warpPerspective(image, M, (image_width, image_height))
image = dst
#cv2.circle(image, (120, 215), 5, (0, 0, 255), -1)
#cv2.circle(image, (138, 910), 5, (0, 0, 255), -1)
#cv2.circle(image, (695, 860), 5, (0, 0, 255), -1)
#cv2.circle(image, (650, 205), 5, (0, 0, 255), -1)
cv2.imshow(window_name, image)
cv2.imwrite("golden_board.jpeg", image)
cv2.waitKey(5000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment