Skip to content

Commit 38cd470

Browse files
committed
show other annotations in verification view
1 parent 4e5cf8d commit 38cd470

File tree

5 files changed

+101
-32
lines changed

5 files changed

+101
-32
lines changed

imagetagger/imagetagger/annotations/static/annotations/js/boundingboxes.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,18 @@ class BoundingBoxes {
1818
this.clear();
1919
calculateImageScale();
2020
color = color || globals.stdColor;
21+
let colors = [];
22+
if (color.constructor === Array) {
23+
colors = color;
24+
if (color.length != annotations.length) {
25+
console.log('wrong number of colors');
26+
return;
27+
}
28+
} else {
29+
for (let i = 0; i < annotations.length; i++) {
30+
colors.push(color);
31+
}
32+
}
2133

2234
if (annotations.length === 0 || !globals.drawAnnotations) {
2335
return;
@@ -29,6 +41,7 @@ class BoundingBoxes {
2941
for (var a in annotations) {
3042

3143
var annotation = annotations[a];
44+
let color = colors[a];
3245
if (annotation.annotation_type.id !== this.annotationTypeId) {
3346
continue;
3447
}

imagetagger/imagetagger/annotations/static/annotations/js/canvas.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,26 @@ class Canvas {
427427
drawExistingAnnotations(annotations, color) {
428428
this.clear();
429429
color = color || globals.stdColor;
430+
let colors = [];
431+
if (color.constructor === Array) {
432+
colors = color;
433+
if (color.length != annotations.length) {
434+
console.log('wrong number of colors');
435+
return;
436+
}
437+
} else {
438+
for (let i = 0; i < annotations.length; i++) {
439+
colors.push(color);
440+
}
441+
}
430442
if (!globals.drawAnnotations) {
431443
return;
432444
}
433-
for (let annotation of annotations) {
445+
for (let i in annotations) {
446+
let annotation = annotations[i];
447+
let color = colors[i];
448+
console.log(annotation);
449+
console.log(color);
434450
if (annotation.annotation_type.id !== this.annotationTypeId) {
435451
continue;
436452
}

imagetagger/imagetagger/annotations/static/annotations/js/verification.js

Lines changed: 44 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ function calculateImageScale() {
2828
let gImageId;
2929
let gImageSet;
3030
let gImageSetId;
31+
let gCurrentAnnotations;
3132
let gImageCache = {};
3233
let gAnnotationId; // the selected annotation
3334
let tool;
@@ -92,16 +93,18 @@ function calculateImageScale() {
9293
})
9394
}
9495

95-
function loadSingleAnnotation(id, fromHistory) {
96+
function loadImageAnnotations(annotation, fromHistory) {
9697
let params = {
97-
annotation_id: id,
98+
image_id: annotation.image.id,
99+
annotation_type_id: annotation.annotation_type,
98100
};
99-
$.ajax(API_ANNOTATIONS_BASE_URL + 'annotation/loadone/?' + $.param(params), {
101+
$.ajax(API_ANNOTATIONS_BASE_URL + 'annotation/loadmultiple/?' + $.param(params), {
100102
type: 'GET',
101103
headers: gHeaders,
102104
dataType: 'json',
103105
success: function (data) {
104-
continueLoadAnnotationView(data.annotation, fromHistory);
106+
gCurrentAnnotations = data.annotation;
107+
continueLoadAnnotationView(annotation.id, fromHistory);
105108
},
106109
error: function () {
107110
displayFeedback($('#feedback_connection_error'))
@@ -130,7 +133,7 @@ function calculateImageScale() {
130133
if (state) {
131134
strState = 'accept';
132135
}
133-
let annotation = gAnnotationList.filter(function(e) {
136+
let annotation = gCurrentAnnotations.filter(function(e) {
134137
return e.id === id;
135138
})[0];
136139
annotation.verified_by_user = true;
@@ -324,11 +327,9 @@ function calculateImageScale() {
324327
annotationIndex += offset;
325328
if (annotationIndex < 0) {
326329
displayFeedback($('#feedback_last_annotation'));
327-
drawAnnotation(gAnnotationList[0]);
328330
return;
329331
} else if (annotationIndex >= annotationIndexList.length) {
330332
displayFeedback($('#feedback_last_annotation'));
331-
drawAnnotation(gAnnotationList[gAnnotationList.length - 1]);
332333
return;
333334
}
334335

@@ -343,19 +344,22 @@ function calculateImageScale() {
343344
*/
344345
function loadAnnotationView(annotationId, fromHistory) {
345346
gAnnotationId = annotationId;
346-
let annotationNotInList = gAnnotationList.filter(function (e) {
347+
let annotation = gAnnotationList.filter(function (e) {
347348
return e.id === annotationId;
348-
}).length === 0;
349-
if (annotationNotInList) {
349+
})[0];
350+
if (!annotation) {
350351
console.log(
351352
'skipping request to load annotation ' + annotationId +
352353
' as it is not in current annotation list.');
353354
return;
354355
}
355-
loadSingleAnnotation(annotationId, fromHistory);
356+
loadImageAnnotations(annotation, fromHistory);
356357
}
357358

358-
function continueLoadAnnotationView(annotation, fromHistory) {
359+
function continueLoadAnnotationView(annotation_id, fromHistory) {
360+
let annotation = gCurrentAnnotations.filter(function (e) {
361+
return e.id === annotation_id;
362+
})[0];
359363
if (annotation.verified_by_user) {
360364
displayFeedback($('#feedback_already_verified'));
361365
}
@@ -396,18 +400,20 @@ function calculateImageScale() {
396400
$('#blurred_label').hide()
397401
}
398402
$('#blurred').prop('checked', annotation.blurred);
399-
drawAnnotation(annotation);
403+
drawAnnotations(gCurrentAnnotations, annotation.id);
400404
}
401405

402406
/**
403-
* Draw the annotation that should be verified
407+
* Draw the annotations that should be verified
404408
*
405-
* @param annotation
409+
* @param annotations list of all annotation to draw
410+
* @param current id of the current annotation
406411
*/
407-
function drawAnnotation(annotation) {
412+
function drawAnnotations(annotations, current) {
408413
if (tool) {
409414
tool.clear();
410415
}
416+
let annotation = annotations[0];
411417
if (!tool || tool.annotationTypeId !== annotation.annotation_type.id ||
412418
(tool.vector_type === 5 && tool.node_count !== annotation.annotation_type.node_count)) {
413419
switch (annotation.annotation_type.vector_type) {
@@ -425,18 +431,25 @@ function calculateImageScale() {
425431
break;
426432
}
427433
}
428-
let color = '#FF0000';
429-
if (annotation.concealed) {
430-
if (annotation.blurred) {
431-
color = '#5CB85C';
432-
} else {
433-
color = '#F0AD4E';
434+
colors = [];
435+
for (let annotation of annotations) {
436+
let color = '#FF0000';
437+
if (annotation.concealed) {
438+
if (annotation.blurred) {
439+
color = '#5CB85C';
440+
} else {
441+
color = '#F0AD4E';
442+
}
434443
}
444+
else if (annotation.blurred) {
445+
color = '#5BC0DE'
446+
}
447+
if (annotation.id !== current) {
448+
color += '60'; // some transparency
449+
}
450+
colors.push(color);
435451
}
436-
else if (annotation.blurred) {
437-
color = '#5BC0DE'
438-
}
439-
tool.drawExistingAnnotations([annotation], color);
452+
tool.drawExistingAnnotations(annotations, colors);
440453
}
441454

442455
/**
@@ -515,7 +528,7 @@ function calculateImageScale() {
515528
}
516529

517530
function handleConcealedChange() {
518-
let annotation = gAnnotationList.filter(function(e) {
531+
let annotation = gCurrentAnnotations.filter(function(e) {
519532
return e.id === gAnnotationId;
520533
})[0];
521534
annotation.concealed = $('#concealed').is(':checked');
@@ -524,12 +537,12 @@ function calculateImageScale() {
524537
} else {
525538
$('#concealed_label').hide()
526539
}
527-
drawAnnotation(annotation);
540+
drawAnnotations(gCurrentAnnotations, annotation.id);
528541
apiBlurredConcealed();
529542
}
530543

531544
function handleBlurredChange() {
532-
let annotation = gAnnotationList.filter(function(e) {
545+
let annotation = gCurrentAnnotations.filter(function(e) {
533546
return e.id === gAnnotationId;
534547
})[0];
535548
annotation.blurred = $('#blurred').is(':checked');
@@ -538,12 +551,12 @@ function calculateImageScale() {
538551
} else {
539552
$('#blurred_label').hide()
540553
}
541-
drawAnnotation(annotation);
554+
drawAnnotations(gCurrentAnnotations, annotation.id);
542555
apiBlurredConcealed();
543556
}
544557

545558
function apiBlurredConcealed() {
546-
let annotation = gAnnotationList.filter(function(e) {
559+
let annotation = gCurrentAnnotations.filter(function(e) {
547560
return e.id === gAnnotationId;
548561
})[0];
549562
let data = {

imagetagger/imagetagger/annotations/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
url(r'^api/annotation/loadsetannotationtypes/$', views.load_set_annotation_types, name='load_set_annotation_types'), # loads annotations of an image
2525
url(r'^api/annotation/loadfilteredset/$', views.load_filtered_set_annotations, name='load_filtered_set_annotations'), # loads filtered annotations of an image
2626
url(r'^api/annotation/loadone/$', views.load_annotation, name='load_annotation'),
27+
url(r'^api/annotation/loadmultiple/$', views.load_multiple_annotations, name='load_multiple_annotations'),
2728
url(r'^api/annotation/verify/$', views.api_verify_annotation, name='verify_annotation'),
2829
url(r'^api/annotation/update/$', views.update_annotation, name='update_annotations'),
2930
url(r'^api/annotation/blurred_concealed/$', views.api_blurred_concealed_annotation, name='blurred_concealed_annotation'),

imagetagger/imagetagger/annotations/views.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,32 @@ def load_annotation(request) -> Response:
769769
}, status=HTTP_200_OK)
770770

771771

772+
@login_required
773+
@api_view(['GET'])
774+
def load_multiple_annotations(request) -> Response:
775+
try:
776+
image_id = int(request.query_params['image_id'])
777+
annotation_type_id = int(request.query_params['annotation_type_id'])
778+
except (KeyError, TypeError, ValueError):
779+
raise ParseError
780+
781+
annotations = Annotation.objects.filter(image_id=image_id, annotation_type_id=annotation_type_id)
782+
783+
if not Image.objects.get(id=image_id).image_set.has_perm('read', request.user):
784+
return Response({
785+
'detail': 'permission for reading this image set missing.',
786+
}, status=HTTP_403_FORBIDDEN)
787+
788+
serializer = AnnotationSerializer(annotations,
789+
context={
790+
'request': request,
791+
},
792+
many=True)
793+
return Response({
794+
'annotation': serializer.data,
795+
}, status=HTTP_200_OK)
796+
797+
772798
@login_required
773799
@api_view(['POST'])
774800
def update_annotation(request) -> Response:

0 commit comments

Comments
 (0)