-
Notifications
You must be signed in to change notification settings - Fork 622
/
Copy pathDetecting_Clicks_On_Images.py
50 lines (35 loc) · 1.28 KB
/
Detecting_Clicks_On_Images.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
################### Simple Detect #############
# import cv2
# def mousePoints(event,x,y,flags,params):
# if event == cv2.EVENT_LBUTTONDOWN:
# print(x,y)
#
# img = cv2.imread('Resources/cards.jpg')
# cv2.imshow("Original Image ", img)
# cv2.setMouseCallback("Original Image ", mousePoints)
# cv2.waitKey(0)
######### WARP PRESPECTIVE IMPLEMANTAION WITH MOUSE CLICKS ##################
import cv2
import numpy as np
circles = np.zeros((4,2),np.int)
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('Resources/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)
imgOutput = cv2.warpPerspective(img,matrix,(width,height))
cv2.imshow("Output Image ", imgOutput)
for x in range (0,4):
cv2.circle(img,(circles[x][0],circles[x][1]),3,(0,255,0),cv2.FILLED)
cv2.imshow("Original Image ", img)
cv2.setMouseCallback("Original Image ", mousePoints)
cv2.waitKey(1)