-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_img1.py
executable file
·78 lines (64 loc) · 3.25 KB
/
test_img1.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
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env python
from opencv_header import *
def onChange(pos):
pass
if __name__ == "__main__":
path = './'
# path = '/home/robit/VS_workspace/capstone/'
# capture = cv2.VideoCapture(-1)
# capture.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
# capture.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)
src = cv2.imread(path + "handle_plus.jpg", cv2.IMREAD_COLOR)
src = cv2.resize(src, dsize=(640, 480), interpolation=cv2.INTER_AREA)
cv2.namedWindow("img_contourBox")
cv2.createTrackbar("h_min", "img_contourBox", 0, 179, onChange)
cv2.createTrackbar("h_max", "img_contourBox", 0, 179, onChange)
cv2.createTrackbar("s_min", "img_contourBox", 0, 255, onChange)
cv2.createTrackbar("s_max", "img_contourBox", 0, 255, onChange)
cv2.createTrackbar("v_min", "img_contourBox", 0, 255, onChange)
cv2.createTrackbar("v_max", "img_contourBox", 0, 255, onChange)
cv2.createTrackbar("blur", "img_contourBox", 5, 15, onChange)
cv2.createTrackbar("g_scale", "img_contourBox", 0, 255, onChange)
cv2.setTrackbarPos("h_min", "img_contourBox", 169)
cv2.setTrackbarPos("h_max", "img_contourBox", 179)
cv2.setTrackbarPos("s_min", "img_contourBox", 109)
cv2.setTrackbarPos("s_max", "img_contourBox", 255)
cv2.setTrackbarPos("v_min", "img_contourBox", 0)
cv2.setTrackbarPos("v_max", "img_contourBox", 255)
cv2.setTrackbarPos("blur", "img_contourBox", 9)
cv2.setTrackbarPos("g_scale", "img_contourBox", 27)
while cv2.waitKey(33) != ord('q'):
# ret, frame = capture.read()
# cv2.imshow("VideoFrame", frame)
height, width, channel = src.shape
low = [169, 109, 0]
high = [179, 255, 255]
low[0] = cv2.getTrackbarPos("h_min", "img_contourBox")
high[0] = cv2.getTrackbarPos("h_max", "img_contourBox")
low[1] = cv2.getTrackbarPos("s_min", "img_contourBox")
high[1] = cv2.getTrackbarPos("s_max", "img_contourBox")
low[2] = cv2.getTrackbarPos("v_min", "img_contourBox")
high[2] = cv2.getTrackbarPos("v_max", "img_contourBox")
blur = cv2.getTrackbarPos("blur", "img_contourBox")
g_scale = cv2.getTrackbarPos("g_scale", "img_contourBox")
img_masked = mask(src, low, high)
cv2.imshow("img_masked", img_masked)
img_blur = Blurring(img_masked, blur)
cv2.imshow('img_blur', img_blur)
img_binary = Grayscale(img_blur, g_scale)
cv2.imshow('img_binary', img_binary)
contours, img_contour = draw_Contours(img_binary, height, width, channel)
cv2.imshow('contours', img_contour)
img_contourBox, angle, cart_size = draw_ContourBox(contours, 300, 3, src)
cv2.imshow('img_contourBox', img_contourBox)
if cv2.waitKey(33) == ord('r'):
cv2.setTrackbarPos("h_min", "img_contourBox", 169)
cv2.setTrackbarPos("h_max", "img_contourBox", 179)
cv2.setTrackbarPos("s_min", "img_contourBox", 109)
cv2.setTrackbarPos("s_max", "img_contourBox", 255)
cv2.setTrackbarPos("v_min", "img_contourBox", 0)
cv2.setTrackbarPos("v_max", "img_contourBox", 255)
cv2.setTrackbarPos("blur", "img_contourBox", 9)
cv2.setTrackbarPos("g_scale", "img_contourBox", 27)
capture.release()
cv2.destroyAllWindows()