-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwarp.py
More file actions
38 lines (32 loc) · 1.28 KB
/
warp.py
File metadata and controls
38 lines (32 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import cv2
import numpy as np
circles = np.zeros((4, 2), np.int)
counter = 0
w, h = 720, 720
image_path = 'C:/Users/ASUS/Desktop/3D_Look/images/'
def mousePoints(event, x, y, flags, params):
global counter
if event == cv2.EVENT_LBUTTONDOWN:
circles[counter] = x * 1.5 + 540, y * 1.5 + 540
counter += 1
print(counter)
# set range based on increment
for i in range(600):
img = cv2.imread(image_path + str(i) + '.png')
while True:
if counter == 4:
counter = 0
pts1 = np.float32([circles[0], circles[1], circles[2], circles[3]])
pts2 = np.float32([[0, 0], [w, 0], [w, h], [0, h]])
matrix = cv2.getPerspectiveTransform(pts1, pts2)
out = cv2.warpPerspective(img, matrix, (w, h))
cv2.imwrite(image_path + 'warped_2/' + str(i) + '.jpg', out)
cv2.imshow("Output Image", out)
if counter > 0:
cv2.destroyWindow("Output Image")
cv2.imshow("Original"+str(i), cv2.resize(img[540:1620, 540:1620], (720, 720)))
cv2.setMouseCallback("Original"+str(i), mousePoints)
if cv2.waitKey(1) & 0xFF == ord('q'):
circles = np.zeros((4, 2), np.int)
cv2.destroyAllWindows()
break