Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show all verifications in verification view #169

Merged
merged 2 commits into from
Dec 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ class BoundingBoxes {
this.clear();
calculateImageScale();
color = color || globals.stdColor;
let colors = [];
if (color.constructor === Array) {
colors = color;
if (color.length != annotations.length) {
console.log('wrong number of colors');
return;
}
} else {
for (let i = 0; i < annotations.length; i++) {
colors.push(color);
}
}

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

var annotation = annotations[a];
let color = colors[a];
if (annotation.annotation_type.id !== this.annotationTypeId) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,26 @@ class Canvas {
drawExistingAnnotations(annotations, color) {
this.clear();
color = color || globals.stdColor;
let colors = [];
if (color.constructor === Array) {
colors = color;
if (color.length != annotations.length) {
console.log('wrong number of colors');
return;
}
} else {
for (let i = 0; i < annotations.length; i++) {
colors.push(color);
}
}
if (!globals.drawAnnotations) {
return;
}
for (let annotation of annotations) {
for (let i in annotations) {
let annotation = annotations[i];
let color = colors[i];
console.log(annotation);
console.log(color);
if (annotation.annotation_type.id !== this.annotationTypeId) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ function calculateImageScale() {
let gImageId;
let gImageSet;
let gImageSetId;
let gCurrentAnnotations;
let gImageCache = {};
let gAnnotationId; // the selected annotation
let tool;
Expand Down Expand Up @@ -92,16 +93,18 @@ function calculateImageScale() {
})
}

function loadSingleAnnotation(id, fromHistory) {
function loadImageAnnotations(annotation, fromHistory) {
let params = {
annotation_id: id,
image_id: annotation.image.id,
annotation_type_id: annotation.annotation_type,
};
$.ajax(API_ANNOTATIONS_BASE_URL + 'annotation/loadone/?' + $.param(params), {
$.ajax(API_ANNOTATIONS_BASE_URL + 'annotation/loadmultiple/?' + $.param(params), {
type: 'GET',
headers: gHeaders,
dataType: 'json',
success: function (data) {
continueLoadAnnotationView(data.annotation, fromHistory);
gCurrentAnnotations = data.annotation;
continueLoadAnnotationView(annotation.id, fromHistory);
},
error: function () {
displayFeedback($('#feedback_connection_error'))
Expand Down Expand Up @@ -130,7 +133,7 @@ function calculateImageScale() {
if (state) {
strState = 'accept';
}
let annotation = gAnnotationList.filter(function(e) {
let annotation = gCurrentAnnotations.filter(function(e) {
return e.id === id;
})[0];
annotation.verified_by_user = true;
Expand Down Expand Up @@ -324,11 +327,9 @@ function calculateImageScale() {
annotationIndex += offset;
if (annotationIndex < 0) {
displayFeedback($('#feedback_last_annotation'));
drawAnnotation(gAnnotationList[0]);
return;
} else if (annotationIndex >= annotationIndexList.length) {
displayFeedback($('#feedback_last_annotation'));
drawAnnotation(gAnnotationList[gAnnotationList.length - 1]);
return;
}

Expand All @@ -343,19 +344,22 @@ function calculateImageScale() {
*/
function loadAnnotationView(annotationId, fromHistory) {
gAnnotationId = annotationId;
let annotationNotInList = gAnnotationList.filter(function (e) {
let annotation = gAnnotationList.filter(function (e) {
return e.id === annotationId;
}).length === 0;
if (annotationNotInList) {
})[0];
if (!annotation) {
console.log(
'skipping request to load annotation ' + annotationId +
' as it is not in current annotation list.');
return;
}
loadSingleAnnotation(annotationId, fromHistory);
loadImageAnnotations(annotation, fromHistory);
}

function continueLoadAnnotationView(annotation, fromHistory) {
function continueLoadAnnotationView(annotation_id, fromHistory) {
let annotation = gCurrentAnnotations.filter(function (e) {
return e.id === annotation_id;
})[0];
if (annotation.verified_by_user) {
displayFeedback($('#feedback_already_verified'));
}
Expand Down Expand Up @@ -396,18 +400,20 @@ function calculateImageScale() {
$('#blurred_label').hide()
}
$('#blurred').prop('checked', annotation.blurred);
drawAnnotation(annotation);
drawAnnotations(gCurrentAnnotations, annotation.id);
}

/**
* Draw the annotation that should be verified
* Draw the annotations that should be verified
*
* @param annotation
* @param annotations list of all annotation to draw
* @param current id of the current annotation
*/
function drawAnnotation(annotation) {
function drawAnnotations(annotations, current) {
if (tool) {
tool.clear();
}
let annotation = annotations[0];
if (!tool || tool.annotationTypeId !== annotation.annotation_type.id ||
(tool.vector_type === 5 && tool.node_count !== annotation.annotation_type.node_count)) {
switch (annotation.annotation_type.vector_type) {
Expand All @@ -425,18 +431,25 @@ function calculateImageScale() {
break;
}
}
let color = '#FF0000';
if (annotation.concealed) {
if (annotation.blurred) {
color = '#5CB85C';
} else {
color = '#F0AD4E';
colors = [];
for (let annotation of annotations) {
let color = '#FF0000';
if (annotation.concealed) {
if (annotation.blurred) {
color = '#5CB85C';
} else {
color = '#F0AD4E';
}
}
else if (annotation.blurred) {
color = '#5BC0DE'
}
if (annotation.id !== current) {
color += '60'; // some transparency
}
colors.push(color);
}
else if (annotation.blurred) {
color = '#5BC0DE'
}
tool.drawExistingAnnotations([annotation], color);
tool.drawExistingAnnotations(annotations, colors);
}

/**
Expand Down Expand Up @@ -515,7 +528,7 @@ function calculateImageScale() {
}

function handleConcealedChange() {
let annotation = gAnnotationList.filter(function(e) {
let annotation = gCurrentAnnotations.filter(function(e) {
return e.id === gAnnotationId;
})[0];
annotation.concealed = $('#concealed').is(':checked');
Expand All @@ -524,12 +537,12 @@ function calculateImageScale() {
} else {
$('#concealed_label').hide()
}
drawAnnotation(annotation);
drawAnnotations(gCurrentAnnotations, annotation.id);
apiBlurredConcealed();
}

function handleBlurredChange() {
let annotation = gAnnotationList.filter(function(e) {
let annotation = gCurrentAnnotations.filter(function(e) {
return e.id === gAnnotationId;
})[0];
annotation.blurred = $('#blurred').is(':checked');
Expand All @@ -538,12 +551,12 @@ function calculateImageScale() {
} else {
$('#blurred_label').hide()
}
drawAnnotation(annotation);
drawAnnotations(gCurrentAnnotations, annotation.id);
apiBlurredConcealed();
}

function apiBlurredConcealed() {
let annotation = gAnnotationList.filter(function(e) {
let annotation = gCurrentAnnotations.filter(function(e) {
return e.id === gAnnotationId;
})[0];
let data = {
Expand Down
1 change: 1 addition & 0 deletions imagetagger/imagetagger/annotations/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
url(r'^api/annotation/loadsetannotationtypes/$', views.load_set_annotation_types, name='load_set_annotation_types'), # loads annotations of an image
url(r'^api/annotation/loadfilteredset/$', views.load_filtered_set_annotations, name='load_filtered_set_annotations'), # loads filtered annotations of an image
url(r'^api/annotation/loadone/$', views.load_annotation, name='load_annotation'),
url(r'^api/annotation/loadmultiple/$', views.load_multiple_annotations, name='load_multiple_annotations'),
url(r'^api/annotation/verify/$', views.api_verify_annotation, name='verify_annotation'),
url(r'^api/annotation/update/$', views.update_annotation, name='update_annotations'),
url(r'^api/annotation/blurred_concealed/$', views.api_blurred_concealed_annotation, name='blurred_concealed_annotation'),
Expand Down
28 changes: 27 additions & 1 deletion imagetagger/imagetagger/annotations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ def load_filtered_set_annotations(request) -> Response:

images = Image.objects.filter(image_set=imageset)
annotations = Annotation.objects.filter(image__in=images,
annotation_type__active=True).order_by('image_id').select_related()
annotation_type__active=True).order_by('image__name', 'id').select_related()
if annotation_type_id > -1:
annotations = annotations.filter(annotation_type__id=annotation_type_id)
if verified:
Expand Down Expand Up @@ -769,6 +769,32 @@ def load_annotation(request) -> Response:
}, status=HTTP_200_OK)


@login_required
@api_view(['GET'])
def load_multiple_annotations(request) -> Response:
try:
image_id = int(request.query_params['image_id'])
annotation_type_id = int(request.query_params['annotation_type_id'])
except (KeyError, TypeError, ValueError):
raise ParseError

annotations = Annotation.objects.filter(image_id=image_id, annotation_type_id=annotation_type_id)

if not Image.objects.get(id=image_id).image_set.has_perm('read', request.user):
return Response({
'detail': 'permission for reading this image set missing.',
}, status=HTTP_403_FORBIDDEN)

serializer = AnnotationSerializer(annotations,
context={
'request': request,
},
many=True)
return Response({
'annotation': serializer.data,
}, status=HTTP_200_OK)


@login_required
@api_view(['POST'])
def update_annotation(request) -> Response:
Expand Down
2 changes: 1 addition & 1 deletion imagetagger/imagetagger/images/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def view_imageset(request, image_set_id):
all_annotation_types = AnnotationType.objects.filter(active=True)
annotations = Annotation.objects.filter(
image__in=images,
annotation_type__active=True).order_by("id")
annotation_type__active=True).order_by('image__name', 'id')
annotation_types = AnnotationType.objects.filter(annotation__image__image_set=imageset, active=True).distinct()\
.annotate(count=Count('annotation'),
in_image_count=Count('annotation', filter=Q(annotation__vector__isnull=False)),
Expand Down