Skip to content

Commit f4ed055

Browse files
author
Andrey Zhavoronkov
committed
code cleanup
1 parent bf1e0a3 commit f4ed055

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

cvat/apps/annotation/annotation.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,21 +102,27 @@ def has_overlap(a, b):
102102

103103
@staticmethod
104104
def _slice_track(track_, start, stop):
105+
def filter_track_shapes(shapes):
106+
drop_count = sum(1 for _ in itertools.takewhile(lambda s: s['outside'], shapes))
107+
return shapes[drop_count:]
108+
105109
track = copy.deepcopy(track_)
106110
segment_shapes = [s for s in track['shapes'] if AnnotationIR._is_shape_inside(s, start, stop)]
111+
segment_shapes = filter_track_shapes(segment_shapes)
107112

108113
if len(segment_shapes) < len(track['shapes']):
109114
interpolated_shapes = TrackManager.get_interpolated_shapes(track, start, stop)
115+
scoped_shapes = [s for s in interpolated_shapes if AnnotationIR._is_shape_inside(s, start, stop)]
116+
scoped_shapes = filter_track_shapes(scoped_shapes)
117+
118+
if scoped_shapes:
119+
if not scoped_shapes[0]['keyframe']:
120+
segment_shapes.insert(0, scoped_shapes[0])
121+
if not scoped_shapes[-1]['keyframe']:
122+
segment_shapes.append(scoped_shapes[-1])
110123

111-
for shape in interpolated_shapes:
112-
if shape['frame'] == start and \
113-
(not segment_shapes or segment_shapes[0]['frame'] > start):
114-
segment_shapes.insert(0, shape)
115-
elif shape['frame'] == stop and \
116-
(not segment_shapes or segment_shapes[-1]['frame'] < stop):
117-
segment_shapes.append(shape)
118-
drop_shape_count = sum(1 for _ in itertools.takewhile(lambda s: s['outside'], segment_shapes))
119-
segment_shapes = segment_shapes[drop_shape_count:]
124+
# Should delete 'interpolation_shapes' and 'keyframe' keys because
125+
# Track and TrackedShape models doen't expect these fields
120126
del track['interpolated_shapes']
121127
for shape in segment_shapes:
122128
del shape['keyframe']

0 commit comments

Comments
 (0)