Skip to content

Commit

Permalink
Disable hot key for inactive tools, closes #63
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbroks committed Jan 16, 2019
1 parent 1a62b37 commit fb85136
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 46 deletions.
4 changes: 3 additions & 1 deletion app/config.py
@@ -1,10 +1,12 @@
import os

from .util.version_util import get_tag


class Config:

NAME = "COCO Annotator"
VERSION = "0.1"
VERSION = get_tag()

# Flask instance
SWAGGER_UI_JSONEDITOR = True
Expand Down
21 changes: 7 additions & 14 deletions app/models.py
Expand Up @@ -204,7 +204,12 @@ def is_empty(self):
def mask(self):
""" Returns binary mask of annotation """
mask = np.zeros((self.height, self.width))
return decode_seg(mask, self.segmentation)
pts = [
np.array(anno).reshape(-1, 2).round().astype(int)
for anno in self.segmentation
]
mask = cv2.fillPoly(mask, pts, 1)
return mask

def clone(self):
""" Creates a clone """
Expand All @@ -215,6 +220,7 @@ def clone(self):


class CategoryModel(db.DynamicDocument):

id = db.SequenceField(primary_key=True)
name = db.StringField(required=True, unique_with=['creator'])
supercategory = db.StringField(default="")
Expand Down Expand Up @@ -367,16 +373,3 @@ def create_from_json(json_file):
dataset_json['categories'] = category_ids
upsert(DatasetModel, query={ "name": name}, update=dataset_json)


def decode_seg(mask, segmentation):
"""
Create binary mask from segmentation
"""
pts = [
np.array(anno).reshape(-1, 2).round().astype(int)
for anno in segmentation
]
mask = cv2.fillPoly(mask, pts, 1)

return mask

1 change: 0 additions & 1 deletion app/util/coco_util.py
Expand Up @@ -88,7 +88,6 @@ def get_image_coco(image):
:param image: ImageModel
:return: Coco in dictionary format
"""
print(DatasetModel, flush=True)
dataset = DatasetModel.objects(id=image.dataset_id).first()
image = fix_ids(image)

Expand Down
1 change: 0 additions & 1 deletion app/util/thumbnail_util.py
Expand Up @@ -2,7 +2,6 @@

from ..models import AnnotationModel
from .color_util import hex_to_rgb
from .coco_util import decode_seg

from PIL import Image

Expand Down
2 changes: 1 addition & 1 deletion client/src/components/annotator/tools/SelectTool.vue
Expand Up @@ -77,7 +77,7 @@ export default {
if (this.hover.annotation == null) return;
let position = this.hover.position.add(this.hover.textShift, 0);
console.log(this.hover.annotation.annotation.id);
if (
this.hover.text == null ||
this.hover.annotation.annotation.id !== this.hover.textId
Expand Down
57 changes: 29 additions & 28 deletions client/src/mixins/shortcuts.js
Expand Up @@ -3,7 +3,7 @@ import { mapMutations } from "vuex";
export default {
data() {
return {
commands: []
commands: [],
};
},
methods: {
Expand All @@ -13,22 +13,22 @@ export default {
{
default: ["arrowup"],
function: this.moveUp,
name: "Move Up Annotaitons"
name: "Move Up Annotaitons",
},
{
default: ["arrowdown"],
function: this.moveDown,
name: "Move Down Annotations"
name: "Move Down Annotations",
},
{
default: ["arrowright"],
function: this.stepIn,
name: "Expand Category"
name: "Expand Category",
},
{
default: ["arrowleft"],
function: this.stepOut,
name: "Collapse Category"
name: "Collapse Category",
},
{
default: ["space"],
Expand All @@ -37,7 +37,7 @@ export default {
if (this.currentCategory) {
this.currentCategory.createAnnotation();
}
}
},
},
{
default: ["delete"],
Expand All @@ -46,98 +46,99 @@ export default {
if (this.currentAnnotation) {
this.currentAnnotation.deleteAnnotation();
}
}
},
},
{
default: ["control", "z"],
name: "Undo Last Action",
function: this.undo
function: this.undo,
},
{
default: ["s"],
name: "Select Tool",
function: () => {
this.activeTool = "Select";
}
},
},
{
default: ["p"],
name: "Polygon Tool",
function: () => {
this.activeTool = "Polygon";
}
if (this.$refs.polygon.isDisabled) wwthis.activeTool = "Polygon";
},
},
{
default: ["w"],
name: "Magic Wand Tool",
function: () => {
this.activeTool = "Magic Wand";
}
if (!this.$refs.magicwand.isDisabled)
this.activeTool = "Magic Wand";
},
},
{
default: ["b"],
name: "Brush Tool",
function: () => {
this.activeTool = "Brush";
}
if (this.$refs.brush.isDisabled) this.activeTool = "Brush";
},
},
{
default: ["e"],
name: "Eraser Tool",
function: () => {
this.activeTool = "Eraser";
}
if (this.$refs.eraser.isDisabled) this.activeTool = "Eraser";
},
},
{
default: ["c"],
name: "Center Image",
function: this.fit
function: this.fit,
},
{
default: ["control", "s"],
name: "Save",
function: this.save
function: this.save,
},
{
title: "Polygon Tool Shortcuts",
default: ["escape"],
name: "Remove Current Polygon",
function: this.$refs.polygon.deletePolygon
function: this.$refs.polygon.deletePolygon,
},
{
title: "Eraser Tool Shortcuts",
default: ["["],
name: "Increase Radius",
function: this.$refs.eraser.increaseRadius
function: this.$refs.eraser.increaseRadius,
},
{
default: ["]"],
name: "Decrease Radius",
function: this.$refs.eraser.decreaseRadius
function: this.$refs.eraser.decreaseRadius,
},
{
title: "Brush Tool Shortcuts",
default: ["["],
name: "Increase Radius",
function: this.$refs.brush.increaseRadius
function: this.$refs.brush.increaseRadius,
},
{
default: ["]"],
name: "Decrease Radius",
function: this.$refs.brush.decreaseRadius
function: this.$refs.brush.decreaseRadius,
},
{
title: "Magic Tool Shortcuts",
default: ["shift", "click"],
name: "Subtract Selection",
readonly: true
}
readonly: true,
},
];
}
},
},
mounted() {
if (this.$route.name === "annotate") {
this.commands = this.annotator();
}
}
},
};

0 comments on commit fb85136

Please sign in to comment.