forked from DrewNF/Tensorflow_Object_Tracking_Video
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtracking_fixed.py
More file actions
97 lines (86 loc) · 4.55 KB
/
tracking_fixed.py
File metadata and controls
97 lines (86 loc) · 4.55 KB
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
def recurrent_track_objects(video_info):
previous_frame= None
previous_num_obj=-1
tracked_video=[]
deltas_video=[]
deltas_frame=[]
dx1,dx2,dy1,dy2=0,0,0,0
# フレームごとの処理
for frame_info in video_info:
print "Tracking Frame Nr: %d"%frame_info.frame # correct
print "Len Rects Frame: %d"%len(frame_info.rects)
current_frame = frame.Frame_Info()
# インスタンスコピー
current_frame=frame_info.duplicate()
# 現在のフレームrectsは初期化
current_frame.rects=[]
trackID=1
# 2フレーム目以降
if previous_frame is not None:
deltas_frame=[]
if frame_info.frame>1:
print "Len Previous Rects Frame: %d"%len(previous_frame.rects)
rect_idx=0
for rect in previous_frame.rects:
print len(current_frame.rects)
# ????
rect.add_delta(deltas_video[frame_info.frame-2][rect_idx][0],deltas_video[frame_info.frame-2][rect_idx][1],deltas_video[frame_info.frame-2][rect_idx][2],deltas_video[frame_info.frame-2][rect_idx][3])
# max_iou rect
current_rect = multiclass_rectangle.pop_max_iou(frame_info.rects,rect)
if current_rect is not None:
# 以前のフレームのrectを代入
current_rect.load_trackID(rect.trackID)
# current rectとprevious rectの差が閾値以上
# current rectを描写し,current_rectの値を更新
## ここも書き換えるひつようがある
## 離れすぎてたらID消す
## current_rectが枠外に出たら IDけす
current_rect.check_rects_motion(frame_info.filename, rect, deltas_video[frame_info.frame-2][rect_idx][0],deltas_video[frame_info.frame-2][rect_idx][1],deltas_video[frame_info.frame-2][rect_idx][2],deltas_video[frame_info.frame-2][rect_idx][3])
# current_rectをcurrent_frameのrectsに追加
current_frame.append_labeled_rect(current_rect)
dx1=current_rect.x1-rect.x1
dx2=current_rect.x2-rect.x2
dy1=current_rect.y1-rect.y1
dy2=current_rect.y2-rect.y2
# 追加
# 3フレーム目から値を代入
deltas_frame.append((dx1,dx2,dy1,dy2))
else: break
#rect += 1
# if previous_frame.rectsをこえたら 新しいIDわりあて
# 2フレーム目
else:
print "Len Previous Rects Frame: %d"%len(previous_frame.rects)
for rect in previous_frame.rects:
print "A"+str(len(current_frame.rects))
current_rect = multiclass_rectangle.pop_max_iou(frame_info.rects,rect)
if current_rect is not None:
dx1=current_rect.x1-rect.x1
dx2=current_rect.x2-rect.x2
dy1=current_rect.y1-rect.y1
dy2=current_rect.y2-rect.y2
deltas_frame.append((dx1,dx2,dy1,dy2))
current_rect.load_trackID(rect.trackID)
# current_rectを追加 initはzero
current_frame.append_labeled_rect(current_rect)
else: break
deltas_video.append(deltas_frame)
# 1フレーム目
else:
picked_rect=Utils_Tensorbox.NMS(frame_info.rects)
# rect: Rectangle_Multiclass Object
# bboxにIDを付加
for rect in picked_rect:
# コピー
current_rect = rect.duplicate()
# rectにidを与える
current_rect.load_trackID(trackID)
# current_rectを追加
current_frame.append_labeled_rect(current_rect)
trackID=trackID+1
previous_frame=current_frame.duplicate()
# rectsのみコピー 上のコピーではrectsはコピーしないので
previous_frame.rects= multiclass_rectangle.duplicate_rects(current_frame.rects)
print "Current Frame obj:%d"%len(current_frame.rects)
tracked_video.insert(len(tracked_video), current_frame)
return tracked_video