-
Notifications
You must be signed in to change notification settings - Fork 0
/
10.workshop.py
67 lines (45 loc) · 1.35 KB
/
10.workshop.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#cam scanner app
import cv2
import numpy as np;
img=cv2.imread("1.jpeg")
print(img)
rows,cols = img.shape[:2]
click_count = 0
a = []
dst_points = np.float32([
[0,0],
[cols-1,0],
[0,rows-1],
[cols-1,rows-1]])
cv2.namedWindow("img",cv2.WINDOW_NORMAL)
cv2.namedWindow("output",cv2.WINDOW_NORMAL)
def draw(event,x,y,flags,param):
global click_count,a
if click_count < 4:
if event == cv2.EVENT_LBUTTONDBLCLK:
print(click_count)
print(x,y)
click_count += 1
a.append((x,y))
else:
src = np.float32([
[a[0][0],a[0][1]],
[a[1][0],a[1][1]],
[a[2][0],a[2][1]],
[a[3][0],a[3][1]]])
click_count = 0
a = []
M = cv2.getPerspectiveTransform(src,dst_points)
img_output = cv2.warpPerspective(img, M, (cols,rows))
img_output = cv2.cvtColor(img_output,cv2.COLOR_BGR2GRAY)
thresh = cv2.adaptiveThreshold(img_output,255,cv2.ADAPTIVE_THRESH_MEAN_C,
cv2.THRESH_BINARY,11,1)
cv2.imshow("output",thresh)
pass
cv2.setMouseCallback("img",draw)
while(1):
cv2.imshow("img",img)
# cv2.imshow("img_output",img_output)
if cv2.waitKey(1) == ord("q"):
break
cv2.destroyAllWindows()