|
3 | 3 | import tkinter as tk
|
4 | 4 | from tkinter.filedialog import *
|
5 | 5 |
|
6 |
| -photo = askopenfilename() # reading the input image |
| 6 | +photo = askopenfilename() # reading the input image |
7 | 7 | img = cv2.imread(photo)
|
8 |
| -img = cv2.resize(img,(500,500)) |
| 8 | +img = cv2.resize(img, (500, 500)) |
9 | 9 |
|
10 |
| -window = tk.Tk() |
| 10 | +window = tk.Tk() |
11 | 11 | window.title("Perspective transform")
|
12 | 12 | window.geometry('350x200')
|
13 | 13 |
|
14 | 14 |
|
15 | 15 | # pts1 is an array storing coordinates of 4 points on the original image
|
16 |
| -pts1 = np.float32([[103,97],[390,93],[85,351],[412,352]]) |
| 16 | +pts1 = np.float32([[103, 97], [390, 93], [85, 351], [412, 352]]) |
17 | 17 | # pts2 is an array storing coordinates of 4 positions where the above points should be after the transformation
|
18 |
| -pts2 = np.float32([[103,97],[390,93],[133,400],[390,400]]) |
| 18 | +pts2 = np.float32([[103, 97], [390, 93], [133, 400], [390, 400]]) |
19 | 19 |
|
20 |
| -Mat = cv2.getPerspectiveTransform(pts1,pts2) |
21 |
| -dst = cv2.warpPerspective(img, Mat, (500,500)) |
| 20 | +Mat = cv2.getPerspectiveTransform(pts1, pts2) |
| 21 | +dst = cv2.warpPerspective(img, Mat, (500, 500)) |
22 | 22 |
|
23 |
| -label = tk.Label(window, text="Points chosen on original image: " + str(pts1)).grid(row=0, column=1) |
24 |
| -label = tk.Label(window, text="Points on transformed image: " + str(pts2)).grid(row=1, column=1) |
25 |
| -label = tk.Label(window, text="The coordinates can be changed in the code ").grid(row=2, column=1) |
| 23 | +label = tk.Label(window, text="Points chosen on original image: " + |
| 24 | + str(pts1)).grid(row=0, column=1) |
| 25 | +label = tk.Label(window, text="Points on transformed image: " + |
| 26 | + str(pts2)).grid(row=1, column=1) |
| 27 | +label = tk.Label(window, text="The coordinates can be changed in the code ").grid( |
| 28 | + row=2, column=1) |
26 | 29 | # displaying the images
|
27 | 30 | cv2.imshow("Original Image", img)
|
28 | 31 | cv2.imshow("Transformed Image", dst)
|
|
0 commit comments