-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScanner.py
More file actions
65 lines (44 loc) · 1.66 KB
/
Scanner.py
File metadata and controls
65 lines (44 loc) · 1.66 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import cv2
import numpy as np
# callback definition
def onClick(event,x,y,flags,param):
if event == cv2.EVENT_LBUTTONDOWN:
if len(src_points) < 4:
src_points.append([x,y])
cv2.circle(img_copy,(x,y), 10 ,(0,0,255), -1)
cv2.imshow("Img", img_copy)
img = cv2.imread("images/gerry.png")
img_copy = img.copy()
# create the satriting points set
src_points = []
# src_points = np.array([
# [28,277],
# [131,987],
# [730,860],
# [572,149]
# ], dtype = np.float32) # passing integers number will rease an error
#? the array have the points in a counter wise order , starting from the top left and
#? ending at the top right corner
# create the destination points
dst_points = np.array([
[0,0],
[0,800],
[600,800],
[600,0]
], dtype = np.float32) # [colums, row]
# show the images to getting the corners
cv2.namedWindow("Img", cv2.WINDOW_KEEPRATIO)
cv2.setMouseCallback("Img", onClick) # assoaciated the onClick function to our window to get the corners
cv2.imshow("Img", img_copy)
cv2.waitKey(0)
# compute the homography matrix
#? it will be the transformation matrix we will applied to the original image
src_float = np.array(src_points, dtype= np.float32) #create a numby array passing as argument a list of python
H = cv2.getPerspectiveTransform(src_float, dst_points)
# apply to original img
output_img = cv2.warpPerspective(img, H,(600,800))
#create the window
cv2.namedWindow("Output", cv2.WINDOW_KEEPRATIO)
cv2.imshow("Img", img)
cv2.imshow("Output", output_img)
cv2.waitKey(0)