-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
104 lines (79 loc) · 2.51 KB
/
main.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import threading
import time
import cv2
from RobotControl import Serial_Servo_Running as SSR
import running_parameters
import levels.first as first
import levels.door as door
import levels.stairs as stairs
import levels.barrier as barrier
import copy
# import all_together_trap_bridge_stairs_lab_changed as all
global param_data, dim, k, d, scale, p, Knew, map1, map2, color_dict, color_range
# 运行参数 #
cap = cv2.VideoCapture(-1)
Running = True
org_img = None
ret = False
level = 1
debug = True
key = -1
istop = True
# 第一关参数 #
door_count = 0
no_door_count = 0
# 第二关参数 #
door_cnt = 0
door_end = 0
def initialize_parameters():
global param_data, dim, k, d, scale, p, Knew, map1, map2, color_dict, color_range
param_data = running_parameters.param_data
dim = running_parameters.dim
k = running_parameters.k
d = running_parameters.d
scale = running_parameters.scale
p = running_parameters.p
Knew = running_parameters.Knew
map1 = running_parameters.map1
map2 = running_parameters.map2
color_dict = running_parameters.color_dict
color_range = running_parameters.color_range
def get_img():
global cap, org_img, ret, Running, key
while True:
if cap.isOpened():
ret, org_img_fish = cap.read()
org_img = cv2.remap(org_img_fish.copy(), map1, map2, interpolation=cv2.INTER_LINEAR,
borderMode=cv2.BORDER_CONSTANT)
if ret:
cv2.imshow('original frame', org_img)
time.sleep(0.6)
key = cv2.waitKey(3)
else:
time.sleep(0.01)
else:
time.sleep(0.01)
def main():
# 初始化参数
initialize_parameters()
# 启动摄像头线程
th1 = threading.Thread(target=get_img)
th1.setDaemon(True) # 设置为后台线程,这里默认是False,设置为True之后则主线程不用等待子线程
th1.start()
# 启动控制线程
SSR.start_action_thread()
print(org_img)
while True:
time.sleep(3)
# test第一关,过杆
# global door_count, no_door_count
# door_count, no_door_count = first.main(door_count, no_door_count,org_img=org_img, debug=debug)
# flip barrier
# global door_count, no_door_count
# barrier.main(org_img=org_img)
# 过蓝色门
# global door_cnt, door_end
# door.find_center_of_next(org_img, door_cnt, door_end)
stairs.main(org_img)
if __name__ == "__main__":
main()