Created
May 13, 2019 03:49
-
-
Save ivder/1b12e9a916b7809775d6c95c95f16ba9 to your computer and use it in GitHub Desktop.
Perspective transform on video
This file contains 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
import cv2 | |
import numpy as np | |
cap = cv2.VideoCapture("test.MP4") | |
out = cv2.VideoWriter('out.mp4', 0x7634706d, 20.0, (960,540)) | |
if (cap.isOpened()==False): | |
print("Error reading video") | |
while (cap.isOpened()): | |
ret, frame = cap.read() | |
if ret == True: | |
pts1 = np.float32([[469, 517], [1317, 517], [1, 676], [1701, 676]]) | |
pts2 = np.float32([[0, 0], [960, 0], [0, 540], [960, 540]]) | |
matrix = cv2.getPerspectiveTransform(pts1, pts2) | |
result = cv2.warpPerspective(frame, matrix, (960, 540)) | |
#cv2.imshow("Frame", frame) | |
cv2.imshow("Perspective transformation", result) | |
out.write(result) | |
if cv2.waitKey(25) & 0xFF == ord('q'): | |
break | |
cap.release() | |
out.release() | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment