-
Notifications
You must be signed in to change notification settings - Fork 0
/
mousePoints.py
33 lines (24 loc) · 894 Bytes
/
mousePoints.py
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
import cv2
import numpy as np
circles = np.zeros((4, 2), np.int32)
counter = 0
def mousePoints(event, x, y, flags, params):
global counter
if event == cv2.EVENT_LBUTTONDOWN:
circles[counter] = x, y
counter = counter + 1
print(circles)
img = cv2.imread("cards.jpg")
while True:
if counter == 4:
width, height = 250, 350
pts1 = np.float32([circles[0], circles[1], circles[2], circles[3]])
pts2 = np.float32([[0, 0], [width, 0], [0, height], [width, height]])
matrix = cv2.getPerspectiveTransform(pts1, pts2)
imgOut = cv2.warpPerspective(img, matrix, (width, height))
cv2.imshow("Output Image", imgOut)
for x in range(0,4):
cv2.circle(img, (circles[x][0],circles[x][1]), 3, (0,0,255), cv2.FILLED)
cv2.imshow("Image", img)
cv2.setMouseCallback("Image", mousePoints)
cv2.waitKey(1)