Skip to content

Commit

Permalink
Merge pull request avinashkranjan#2946 from avinashkranjan/deepsource…
Browse files Browse the repository at this point in the history
…-transform-8b177a6a

format code with autopep8
  • Loading branch information
avinashkranjan committed Aug 10, 2023
2 parents adb1ab2 + 5d247f6 commit f4c65ce
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions Perspective_transform/perspective_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,29 @@
import tkinter as tk
from tkinter.filedialog import *

photo = askopenfilename() # reading the input image
photo = askopenfilename() # reading the input image
img = cv2.imread(photo)
img = cv2.resize(img,(500,500))
img = cv2.resize(img, (500, 500))

window = tk.Tk()
window = tk.Tk()
window.title("Perspective transform")
window.geometry('350x200')


# pts1 is an array storing coordinates of 4 points on the original image
pts1 = np.float32([[103,97],[390,93],[85,351],[412,352]])
pts1 = np.float32([[103, 97], [390, 93], [85, 351], [412, 352]])
# pts2 is an array storing coordinates of 4 positions where the above points should be after the transformation
pts2 = np.float32([[103,97],[390,93],[133,400],[390,400]])
pts2 = np.float32([[103, 97], [390, 93], [133, 400], [390, 400]])

Mat = cv2.getPerspectiveTransform(pts1,pts2)
dst = cv2.warpPerspective(img, Mat, (500,500))
Mat = cv2.getPerspectiveTransform(pts1, pts2)
dst = cv2.warpPerspective(img, Mat, (500, 500))

label = tk.Label(window, text="Points chosen on original image: " + str(pts1)).grid(row=0, column=1)
label = tk.Label(window, text="Points on transformed image: " + str(pts2)).grid(row=1, column=1)
label = tk.Label(window, text="The coordinates can be changed in the code ").grid(row=2, column=1)
label = tk.Label(window, text="Points chosen on original image: " +
str(pts1)).grid(row=0, column=1)
label = tk.Label(window, text="Points on transformed image: " +
str(pts2)).grid(row=1, column=1)
label = tk.Label(window, text="The coordinates can be changed in the code ").grid(
row=2, column=1)
# displaying the images
cv2.imshow("Original Image", img)
cv2.imshow("Transformed Image", dst)
Expand Down

0 comments on commit f4c65ce

Please sign in to comment.