From 076899afa3f6ca82da6cb00377163d01093319a5 Mon Sep 17 00:00:00 2001 From: Boris Sekachev <40690378+bsekachev@users.noreply.github.com> Date: Fri, 23 Nov 2018 18:50:26 +0300 Subject: [PATCH] Some minor fixes (#212) * Fixed: single point wasn't created in right scenario, double press N (without any point) created a point * Fixed: merge didn't create outside objects in some cases * Fixed: split didn't work right * Object selection propagated to next frame --- .../static/engine/js/shapeCollection.js | 1 + .../engine/static/engine/js/shapeCreator.js | 15 ++++++++++++--- .../engine/static/engine/js/shapeMerger.js | 19 ++++++++++++------- .../engine/static/engine/js/shapeSplitter.js | 17 ++++++++++++----- 4 files changed, 37 insertions(+), 15 deletions(-) diff --git a/cvat/apps/engine/static/engine/js/shapeCollection.js b/cvat/apps/engine/static/engine/js/shapeCollection.js index 299fe3b8..164cc387 100644 --- a/cvat/apps/engine/static/engine/js/shapeCollection.js +++ b/cvat/apps/engine/static/engine/js/shapeCollection.js @@ -525,6 +525,7 @@ class ShapeCollectionModel extends Listener { } this._frame = frame; this._interpolate(); + this.selectShape(this._lastPos, false); } else { this._clear(); diff --git a/cvat/apps/engine/static/engine/js/shapeCreator.js b/cvat/apps/engine/static/engine/js/shapeCreator.js index 53408080..28079b66 100644 --- a/cvat/apps/engine/static/engine/js/shapeCreator.js +++ b/cvat/apps/engine/static/engine/js/shapeCreator.js @@ -245,6 +245,8 @@ class ShapeCreatorView { y: null, }; + let numberOfPoints = 0; + if (this._polyShapeSize) { let size = this._polyShapeSize; let sizeDecrement = function() { @@ -272,6 +274,7 @@ class ShapeCreatorView { x: e.detail.event.clientX, y: e.detail.event.clientY, }; + numberOfPoints ++; }); this._drawInstance.on('drawpoint', (e) => { @@ -279,17 +282,23 @@ class ShapeCreatorView { x: e.detail.event.clientX, y: e.detail.event.clientY, }; + numberOfPoints ++; }); this._frameContent.on('mousedown.shapeCreator', (e) => { if (e.which === 3) { + let lenBefore = this._drawInstance.array().value.length; this._drawInstance.draw('undo'); + let lenAfter = this._drawInstance.array().value.length; + if (lenBefore != lenAfter) { + numberOfPoints --; + } } }); this._frameContent.on('mousemove.shapeCreator', (e) => { - if (e.shiftKey && this._type != 'points') { + if (e.shiftKey && ['polygon', 'polyline'].includes(this._type)) { if (lastPoint.x === null || lastPoint.y === null) { this._drawInstance.draw('point', e); } @@ -339,9 +348,9 @@ class ShapeCreatorView { let w = polybox.width; let h = polybox.height; let area = w * h; - let type = this.type; + let type = this._type; - if (area >= AREA_TRESHOLD || type === 'points' || type === 'polyline' && (w >= AREA_TRESHOLD || h >= AREA_TRESHOLD)) { + if (area >= AREA_TRESHOLD || type === 'points' && numberOfPoints || type === 'polyline' && (w >= AREA_TRESHOLD || h >= AREA_TRESHOLD)) { this._controller.finish({points: actualPoints}, type); } } diff --git a/cvat/apps/engine/static/engine/js/shapeMerger.js b/cvat/apps/engine/static/engine/js/shapeMerger.js index f3012cb5..8688c237 100644 --- a/cvat/apps/engine/static/engine/js/shapeMerger.js +++ b/cvat/apps/engine/static/engine/js/shapeMerger.js @@ -134,14 +134,19 @@ class ShapeMergerModel extends Listener { } ) ); - } - // if last is annotation box, push outside - if (shapeDict[sortedFrames[sortedFrames.length - 1]].shape.type === 'annotation_box') { - let copy = Object.assign({}, object.shapes[object.shapes.length - 1]); - copy.outside = true; - copy.frame += 1; - object.shapes.push(copy); + // push an outsided box after each annotation box if next frame is empty + let nextFrame = frame + 1; + let stopFrame = window.cvat.player.frames.stop; + let type = shapeDict[frame].shape.type; + if (type === 'annotation_box' && !(nextFrame in shapeDict) && nextFrame <= stopFrame) { + let copy = Object.assign({}, object.shapes[object.shapes.length - 1]); + copy.outside = true; + copy.frame += 1; + copy.z_order = this._collectionModel.zOrder(frame).max; + copy.attributes = []; + object.shapes.push(copy); + } } Logger.addEvent(Logger.EventType.mergeObjects, { diff --git a/cvat/apps/engine/static/engine/js/shapeSplitter.js b/cvat/apps/engine/static/engine/js/shapeSplitter.js index e32e83d2..ff6dbe5e 100644 --- a/cvat/apps/engine/static/engine/js/shapeSplitter.js +++ b/cvat/apps/engine/static/engine/js/shapeSplitter.js @@ -28,7 +28,7 @@ class ShapeSplitter { split(track, frame) { let keyFrames = track.keyframes.sort((a,b) => a - b); let exported = track.export(); - if (frame > keyFrames[0]) { + if (frame > +keyFrames[0]) { let curInterpolation = track.interpolate(frame); let prevInterpolation = track.interpolate(frame - 1); let curAttributes = this._convertMutableAttributes(curInterpolation.attributes); @@ -45,12 +45,19 @@ class ShapeSplitter { } } - if (!prevInterpolation.position.outside && track.type.split('_')[1] === 'box') { - prevPositionList.push(Object.assign(prevInterpolation.position, { - outside: true, - frame: frame, + if (track.type.split('_')[1] === 'box') { + prevPositionList.push(Object.assign({}, prevInterpolation.position, { + frame: frame - 1, attributes: prevAttrributes, })); + + if (!prevInterpolation.position.outside) { + prevPositionList.push(Object.assign({}, prevInterpolation.position, { + outside: true, + frame: frame, + attributes: [], + })); + } } curPositionList.push(Object.assign(curInterpolation.position, {