1
+ # owner2plusai
2
+
3
+ import cv2 as cv
4
+ import numpy as np
5
+
6
+ circles = np .zeros ((4 ,2 ) ,np .int32 )
7
+ counter_ = 0
8
+ # read mouse click
9
+ def mousePoint (event ,x ,y , flags ,params ):
10
+ global counter_
11
+ if event == cv .EVENT_LBUTTONDOWN :
12
+ circles [counter_ ] = x ,y
13
+ counter_ += 1
14
+
15
+ # read image file
16
+ img = cv .imread ('src/1.jpg' )
17
+ while True :
18
+ if counter_ == 4 :
19
+ width , hight = 500 , 600
20
+ pts1 = np .float32 ([circles [0 ] , circles [1 ] , circles [2 ] ,circles [3 ]]) # side of the image
21
+ pts2 = np .float32 ([[0 ,0 ] ,[width ,0 ] ,[0 ,hight ] ,[width ,hight ]]) # need list
22
+ # getPerspectiveTransform of image
23
+ metrix = cv .getPerspectiveTransform (pts1 , pts2 )
24
+ imgoutput = cv .warpPerspective (img , metrix ,(width , hight ))
25
+ cv .imshow ("result" , imgoutput )
26
+
27
+ for x in range (0 ,4 ):
28
+ cv .circle (img ,(circles [x ][0 ] , circles [x ][1 ]) , 5 , (0 ,200 ,255 ) , cv .FILLED )
29
+
30
+ cv .imshow ('image' , img )
31
+ cv .setMouseCallback ("image" ,mousePoint )
32
+ if cv .waitKey (1 ) & 0xFF == ord ('q' ):
33
+ break
34
+
35
+ cv .destroyAllWindows ()
0 commit comments