Skip to content

Commit f2f09c1

Browse files
committed
show other annotations in verification view
1 parent 684a38a commit f2f09c1

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'))
@@ -147,7 +150,7 @@ function calculateImageScale() {
147150
if (state) {
148151
strState = 'accept';
149152
}
150-
let annotation = gAnnotationList.filter(function(e) {
153+
let annotation = gCurrentAnnotations.filter(function(e) {
151154
return e.id === id;
152155
})[0];
153156
annotation.verified_by_user = true;
@@ -341,11 +344,9 @@ function calculateImageScale() {
341344
annotationIndex += offset;
342345
if (annotationIndex < 0) {
343346
displayFeedback($('#feedback_last_annotation'));
344-
drawAnnotation(gAnnotationList[0]);
345347
return;
346348
} else if (annotationIndex >= annotationIndexList.length) {
347349
displayFeedback($('#feedback_last_annotation'));
348-
drawAnnotation(gAnnotationList[gAnnotationList.length - 1]);
349350
return;
350351
}
351352

@@ -360,19 +361,22 @@ function calculateImageScale() {
360361
*/
361362
function loadAnnotationView(annotationId, fromHistory) {
362363
gAnnotationId = annotationId;
363-
let annotationNotInList = gAnnotationList.filter(function (e) {
364+
let annotation = gAnnotationList.filter(function (e) {
364365
return e.id === annotationId;
365-
}).length === 0;
366-
if (annotationNotInList) {
366+
})[0];
367+
if (!annotation) {
367368
console.log(
368369
'skipping request to load annotation ' + annotationId +
369370
' as it is not in current annotation list.');
370371
return;
371372
}
372-
loadSingleAnnotation(annotationId, fromHistory);
373+
loadImageAnnotations(annotation, fromHistory);
373374
}
374375

375-
function continueLoadAnnotationView(annotation, fromHistory) {
376+
function continueLoadAnnotationView(annotation_id, fromHistory) {
377+
let annotation = gCurrentAnnotations.filter(function (e) {
378+
return e.id === annotation_id;
379+
})[0];
376380
if (annotation.verified_by_user) {
377381
displayFeedback($('#feedback_already_verified'));
378382
}
@@ -413,18 +417,20 @@ function calculateImageScale() {
413417
$('#blurred_label').hide()
414418
}
415419
$('#blurred').prop('checked', annotation.blurred);
416-
drawAnnotation(annotation);
420+
drawAnnotations(gCurrentAnnotations, annotation.id);
417421
}
418422

419423
/**
420-
* Draw the annotation that should be verified
424+
* Draw the annotations that should be verified
421425
*
422-
* @param annotation
426+
* @param annotations list of all annotation to draw
427+
* @param current id of the current annotation
423428
*/
424-
function drawAnnotation(annotation) {
429+
function drawAnnotations(annotations, current) {
425430
if (tool) {
426431
tool.clear();
427432
}
433+
let annotation = annotations[0];
428434
if (!tool || tool.annotationTypeId !== annotation.annotation_type.id ||
429435
(tool.vector_type === 5 && tool.node_count !== annotation.annotation_type.node_count)) {
430436
switch (annotation.annotation_type.vector_type) {
@@ -442,18 +448,25 @@ function calculateImageScale() {
442448
break;
443449
}
444450
}
445-
let color = '#FF0000';
446-
if (annotation.concealed) {
447-
if (annotation.blurred) {
448-
color = '#5CB85C';
449-
} else {
450-
color = '#F0AD4E';
451+
colors = [];
452+
for (let annotation of annotations) {
453+
let color = '#FF0000';
454+
if (annotation.concealed) {
455+
if (annotation.blurred) {
456+
color = '#5CB85C';
457+
} else {
458+
color = '#F0AD4E';
459+
}
451460
}
461+
else if (annotation.blurred) {
462+
color = '#5BC0DE'
463+
}
464+
if (annotation.id !== current) {
465+
color += '60'; // some transparency
466+
}
467+
colors.push(color);
452468
}
453-
else if (annotation.blurred) {
454-
color = '#5BC0DE'
455-
}
456-
tool.drawExistingAnnotations([annotation], color);
469+
tool.drawExistingAnnotations(annotations, colors);
457470
}
458471

459472
/**
@@ -532,7 +545,7 @@ function calculateImageScale() {
532545
}
533546

534547
function handleConcealedChange() {
535-
let annotation = gAnnotationList.filter(function(e) {
548+
let annotation = gCurrentAnnotations.filter(function(e) {
536549
return e.id === gAnnotationId;
537550
})[0];
538551
annotation.concealed = $('#concealed').is(':checked');
@@ -541,12 +554,12 @@ function calculateImageScale() {
541554
} else {
542555
$('#concealed_label').hide()
543556
}
544-
drawAnnotation(annotation);
557+
drawAnnotations(gCurrentAnnotations, annotation.id);
545558
apiBlurredConcealed();
546559
}
547560

548561
function handleBlurredChange() {
549-
let annotation = gAnnotationList.filter(function(e) {
562+
let annotation = gCurrentAnnotations.filter(function(e) {
550563
return e.id === gAnnotationId;
551564
})[0];
552565
annotation.blurred = $('#blurred').is(':checked');
@@ -555,12 +568,12 @@ function calculateImageScale() {
555568
} else {
556569
$('#blurred_label').hide()
557570
}
558-
drawAnnotation(annotation);
571+
drawAnnotations(gCurrentAnnotations, annotation.id);
559572
apiBlurredConcealed();
560573
}
561574

562575
function apiBlurredConcealed() {
563-
let annotation = gAnnotationList.filter(function(e) {
576+
let annotation = gCurrentAnnotations.filter(function(e) {
564577
return e.id === gAnnotationId;
565578
})[0];
566579
let data = {

imagetagger/imagetagger/annotations/urls.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
url(r'^api/annotation/loadsetannotationtypes/$', views.load_set_annotation_types, name='load_set_annotation_types'), # loads annotations of an image
2727
url(r'^api/annotation/loadfilteredset/$', views.load_filtered_set_annotations, name='load_filtered_set_annotations'), # loads filtered annotations of an image
2828
url(r'^api/annotation/loadone/$', views.load_annotation, name='load_annotation'),
29+
url(r'^api/annotation/loadmultiple/$', views.load_multiple_annotations, name='load_multiple_annotations'),
2930
url(r'^api/annotation/verify/$', views.api_verify_annotation, name='verify_annotation'),
3031
url(r'^api/annotation/update/$', views.update_annotation, name='update_annotations'),
3132
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)