Skip to content

Commit fb85136

Browse files
committed
Disable hot key for inactive tools, closes #63
1 parent 1a62b37 commit fb85136

File tree

6 files changed

+40
-46
lines changed

6 files changed

+40
-46
lines changed

app/config.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import os
22

3+
from .util.version_util import get_tag
4+
35

46
class Config:
57

68
NAME = "COCO Annotator"
7-
VERSION = "0.1"
9+
VERSION = get_tag()
810

911
# Flask instance
1012
SWAGGER_UI_JSONEDITOR = True

app/models.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,12 @@ def is_empty(self):
204204
def mask(self):
205205
""" Returns binary mask of annotation """
206206
mask = np.zeros((self.height, self.width))
207-
return decode_seg(mask, self.segmentation)
207+
pts = [
208+
np.array(anno).reshape(-1, 2).round().astype(int)
209+
for anno in self.segmentation
210+
]
211+
mask = cv2.fillPoly(mask, pts, 1)
212+
return mask
208213

209214
def clone(self):
210215
""" Creates a clone """
@@ -215,6 +220,7 @@ def clone(self):
215220

216221

217222
class CategoryModel(db.DynamicDocument):
223+
218224
id = db.SequenceField(primary_key=True)
219225
name = db.StringField(required=True, unique_with=['creator'])
220226
supercategory = db.StringField(default="")
@@ -367,16 +373,3 @@ def create_from_json(json_file):
367373
dataset_json['categories'] = category_ids
368374
upsert(DatasetModel, query={ "name": name}, update=dataset_json)
369375

370-
371-
def decode_seg(mask, segmentation):
372-
"""
373-
Create binary mask from segmentation
374-
"""
375-
pts = [
376-
np.array(anno).reshape(-1, 2).round().astype(int)
377-
for anno in segmentation
378-
]
379-
mask = cv2.fillPoly(mask, pts, 1)
380-
381-
return mask
382-

app/util/coco_util.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ def get_image_coco(image):
8888
:param image: ImageModel
8989
:return: Coco in dictionary format
9090
"""
91-
print(DatasetModel, flush=True)
9291
dataset = DatasetModel.objects(id=image.dataset_id).first()
9392
image = fix_ids(image)
9493

app/util/thumbnail_util.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
from ..models import AnnotationModel
44
from .color_util import hex_to_rgb
5-
from .coco_util import decode_seg
65

76
from PIL import Image
87

client/src/components/annotator/tools/SelectTool.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ export default {
7777
if (this.hover.annotation == null) return;
7878
7979
let position = this.hover.position.add(this.hover.textShift, 0);
80-
console.log(this.hover.annotation.annotation.id);
80+
8181
if (
8282
this.hover.text == null ||
8383
this.hover.annotation.annotation.id !== this.hover.textId

client/src/mixins/shortcuts.js

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { mapMutations } from "vuex";
33
export default {
44
data() {
55
return {
6-
commands: []
6+
commands: [],
77
};
88
},
99
methods: {
@@ -13,22 +13,22 @@ export default {
1313
{
1414
default: ["arrowup"],
1515
function: this.moveUp,
16-
name: "Move Up Annotaitons"
16+
name: "Move Up Annotaitons",
1717
},
1818
{
1919
default: ["arrowdown"],
2020
function: this.moveDown,
21-
name: "Move Down Annotations"
21+
name: "Move Down Annotations",
2222
},
2323
{
2424
default: ["arrowright"],
2525
function: this.stepIn,
26-
name: "Expand Category"
26+
name: "Expand Category",
2727
},
2828
{
2929
default: ["arrowleft"],
3030
function: this.stepOut,
31-
name: "Collapse Category"
31+
name: "Collapse Category",
3232
},
3333
{
3434
default: ["space"],
@@ -37,7 +37,7 @@ export default {
3737
if (this.currentCategory) {
3838
this.currentCategory.createAnnotation();
3939
}
40-
}
40+
},
4141
},
4242
{
4343
default: ["delete"],
@@ -46,98 +46,99 @@ export default {
4646
if (this.currentAnnotation) {
4747
this.currentAnnotation.deleteAnnotation();
4848
}
49-
}
49+
},
5050
},
5151
{
5252
default: ["control", "z"],
5353
name: "Undo Last Action",
54-
function: this.undo
54+
function: this.undo,
5555
},
5656
{
5757
default: ["s"],
5858
name: "Select Tool",
5959
function: () => {
6060
this.activeTool = "Select";
61-
}
61+
},
6262
},
6363
{
6464
default: ["p"],
6565
name: "Polygon Tool",
6666
function: () => {
67-
this.activeTool = "Polygon";
68-
}
67+
if (this.$refs.polygon.isDisabled) wwthis.activeTool = "Polygon";
68+
},
6969
},
7070
{
7171
default: ["w"],
7272
name: "Magic Wand Tool",
7373
function: () => {
74-
this.activeTool = "Magic Wand";
75-
}
74+
if (!this.$refs.magicwand.isDisabled)
75+
this.activeTool = "Magic Wand";
76+
},
7677
},
7778
{
7879
default: ["b"],
7980
name: "Brush Tool",
8081
function: () => {
81-
this.activeTool = "Brush";
82-
}
82+
if (this.$refs.brush.isDisabled) this.activeTool = "Brush";
83+
},
8384
},
8485
{
8586
default: ["e"],
8687
name: "Eraser Tool",
8788
function: () => {
88-
this.activeTool = "Eraser";
89-
}
89+
if (this.$refs.eraser.isDisabled) this.activeTool = "Eraser";
90+
},
9091
},
9192
{
9293
default: ["c"],
9394
name: "Center Image",
94-
function: this.fit
95+
function: this.fit,
9596
},
9697
{
9798
default: ["control", "s"],
9899
name: "Save",
99-
function: this.save
100+
function: this.save,
100101
},
101102
{
102103
title: "Polygon Tool Shortcuts",
103104
default: ["escape"],
104105
name: "Remove Current Polygon",
105-
function: this.$refs.polygon.deletePolygon
106+
function: this.$refs.polygon.deletePolygon,
106107
},
107108
{
108109
title: "Eraser Tool Shortcuts",
109110
default: ["["],
110111
name: "Increase Radius",
111-
function: this.$refs.eraser.increaseRadius
112+
function: this.$refs.eraser.increaseRadius,
112113
},
113114
{
114115
default: ["]"],
115116
name: "Decrease Radius",
116-
function: this.$refs.eraser.decreaseRadius
117+
function: this.$refs.eraser.decreaseRadius,
117118
},
118119
{
119120
title: "Brush Tool Shortcuts",
120121
default: ["["],
121122
name: "Increase Radius",
122-
function: this.$refs.brush.increaseRadius
123+
function: this.$refs.brush.increaseRadius,
123124
},
124125
{
125126
default: ["]"],
126127
name: "Decrease Radius",
127-
function: this.$refs.brush.decreaseRadius
128+
function: this.$refs.brush.decreaseRadius,
128129
},
129130
{
130131
title: "Magic Tool Shortcuts",
131132
default: ["shift", "click"],
132133
name: "Subtract Selection",
133-
readonly: true
134-
}
134+
readonly: true,
135+
},
135136
];
136-
}
137+
},
137138
},
138139
mounted() {
139140
if (this.$route.name === "annotate") {
140141
this.commands = this.annotator();
141142
}
142-
}
143+
},
143144
};

0 commit comments

Comments
 (0)