Created
March 17, 2019 00:13
-
-
Save ChongyeWang/8b84ae0c65346b4d34df9f7c01ab9af7 to your computer and use it in GitHub Desktop.
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 | |
import matplotlib.pyplot as plt | |
image = cv2.imread('images/scan.jpg') | |
cv2.imshow('Original', image) | |
cv2.waitKey(0) | |
# Cordinates of the 4 corners of the original image | |
points_A = np.float32([[320,15], [700,215], [85,610], [530,780]]) | |
# Cordinates of the 4 corners of the desired output | |
# We use a ratio of an A4 Paper 1 : 1.41 | |
points_B = np.float32([[0,0], [420,0], [0,594], [420,594]]) | |
# Use the two sets of four points to compute | |
# the Perspective Transformation matrix, M | |
M = cv2.getPerspectiveTransform(points_A, points_B) | |
warped = cv2.warpPerspective(image, M, (420,594)) | |
cv2.imshow('warpPerspective', warped) | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() | |
import cv2 | |
import numpy as np | |
import matplotlib.pyplot as plt | |
image = cv2.imread('images/ex2.jpg') | |
rows,cols,ch = image.shape | |
cv2.imshow('Original', image) | |
cv2.waitKey(0) | |
# Cordinates of the 4 corners of the original image | |
points_A = np.float32([[320,15], [700,215], [85,610]]) | |
# Cordinates of the 4 corners of the desired output | |
# We use a ratio of an A4 Paper 1 : 1.41 | |
points_B = np.float32([[0,0], [420,0], [0,594]]) | |
# Use the two sets of four points to compute | |
# the Perspective Transformation matrix, M | |
M = cv2.getAffineTransform(points_A, points_B) | |
warped = cv2.warpAffine(image, M, (cols, rows)) | |
cv2.imshow('warpPerspective', warped) | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment