-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathauto_tracking.py
70 lines (51 loc) · 1.73 KB
/
auto_tracking.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
# 自动追踪标识程序
import time
from model import pm_model
from devices import car_devices
from tool import draw_bbox, load_label_list
from preprocess import preprocess_det
if __name__ == "__main__":
# 初始化变量
count = 0
# 初始化设备
car = car_devices()
# 加载模型
ssd_lite = pm_model(data_shape=(1, 3, 128, 128), model_flie='./ssd_lite/model', param_file='./ssd_lite/params')
# 加载标签列表
label_list = load_label_list('./ssd_lite/label_list.txt')
# 等待启动指令
car.wait2start()
# 启动前预热
for _ in range(30):
frame = car.read_frame()
tmp = preprocess_det(frame, (128, 128))
tmp = ssd_lite.predict(tmp)
del frame, tmp
# 主程序
while count<500:
# 初始化状态
state = 'stop'
count += 1
# 模型预测
frame = car.read_frame()
img = preprocess_det(frame, (128, 128))
result_det = ssd_lite.predict(img)
# 预测结果后处理
results_list = draw_bbox(result_det, frame=None, label_list=label_list, draw_threshold=0.7, frame_shape=[120, 160])
# 追踪限速标志
if 'limit_10' in results_list:
dx = results_list['limit_10'][0]-80
if abs(dx)>25:
if dx>0:
state = 'right'
else:
state = 'left'
# 发送转动信息
if state=='right':
car.lib.send_cmd(1530,500)
elif state=='left':
car.lib.send_cmd(1530,2500)
else:
car.lib.send_cmd(1500,1500)
# 停车
car.lib.send_cmd(1500,1500)