-
Notifications
You must be signed in to change notification settings - Fork 0
/
Image.py
66 lines (57 loc) · 2.05 KB
/
Image.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
import cv2
import numpy as np
import matplotlib.pyplot as plt
import tensorflow as tf
def nothing(x):
pass
def dynamic(can):
zeroimg = np.zeros_like(can, dtype=np.uint8)
cv2.namedWindow('canny')
# can = cv2.GaussianBlur(can[:, :, 2], (3, 3), 0)
cv2.createTrackbar('RLower', 'canny', 0, 255, nothing)
cv2.createTrackbar('RUpper', 'canny', 0, 255, nothing)
cv2.createTrackbar('GLower', 'canny', 0, 255, nothing)
cv2.createTrackbar('GUpper', 'canny', 0, 255, nothing)
cv2.createTrackbar('BLower', 'canny', 0, 255, nothing)
cv2.createTrackbar('BUpper', 'canny', 0, 255, nothing)
bcan = can[:, :, 0]
gcan = can[:, :, 1]
rcan = can[:, :, 2]
while 1:
cv2.imshow('canny', zeroimg)
cv2.imshow('img', can)
k = cv2.waitKey(1) & 0xFF
if k == 27:
break
rl = cv2.getTrackbarPos('RLower', 'canny')
ru = cv2.getTrackbarPos('RUpper', 'canny')
bl = cv2.getTrackbarPos('BLower', 'canny')
bu = cv2.getTrackbarPos('BUpper', 'canny')
gl = cv2.getTrackbarPos('GLower', 'canny')
gu = cv2.getTrackbarPos('GUpper', 'canny')
zeroimg[((can[:, :, 0] > bl) & (can[:, :, 0] < bu)) | ((can[:, :, 1] > gl) & (can[:, :, 1] < gu)) |
((can[:, :, 2] > rl) & (can[:, :, 2] < ru))] = 250
images = np.load('OrigXTrain.npy')
img = images[2100]
img = img[60:140, :]
# plt.imshow(img)
# plt.show()
# gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# canny = cv2.Canny(gray, 150, 200)
# plt.imshow(canny)
# plt.show()
src = np.array([[100, 0], [0, 40], [310, 40], [220, 0]], dtype='float32')
dst = np.array([[0, 0], [0, 79], [319, 79], [319, 0]], dtype='float32')
M = cv2.getPerspectiveTransform(src, dst)
# warpimg = cv2.warpPerspective(img, M, dsize=(320, 80))
# plt.imshow(warpimg[:, :, 2], cmap='gray')
# plt.show()
# plt.imshow(warpimg)
# plt.show()
# # gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# # plt.imshow(gray, cmap='gray')
# # plt.show()
# canny = cv2.warpPerspective(canny, M, dsize=(320, 80))
# plt.imshow(canny, cmap='gray')
# plt.show()
dynamic(img)