You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2020/08/27 20:18:06 UTC
[incubator-streampipes] branch dev updated: Change behaviour of
coco files in image labeler
This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes.git
The following commit(s) were added to refs/heads/dev by this push:
new 6bde071 Change behaviour of coco files in image labeler
6bde071 is described below
commit 6bde071429c1b3393e16c000afd07d600590128c
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Thu Aug 27 22:17:33 2020 +0200
Change behaviour of coco files in image labeler
---
.../image-labeling/image-labeling.component.html | 2 +-
.../image-labeling/image-labeling.component.ts | 42 ++++++++++------------
2 files changed, 20 insertions(+), 24 deletions(-)
diff --git a/ui/src/app/core-ui/image/image-labeling/image-labeling.component.html b/ui/src/app/core-ui/image/image-labeling/image-labeling.component.html
index 85fa605..005943f 100644
--- a/ui/src/app/core-ui/image/image-labeling/image-labeling.component.html
+++ b/ui/src/app/core-ui/image/image-labeling/image-labeling.component.html
@@ -64,7 +64,7 @@
</div>
<sp-image-annotations style="width: 270px"
- [annotations]="this.cocoFiles[this.imagesIndex]?.annotations"
+ [annotations]="this.cocoFile?.annotations"
[labels]="labels"
(changeAnnotationLabel)="handleChangeAnnotationLabel($event)"
(deleteAnnotation)="handleDeleteAnnotation($event)">
diff --git a/ui/src/app/core-ui/image/image-labeling/image-labeling.component.ts b/ui/src/app/core-ui/image/image-labeling/image-labeling.component.ts
index 37e66fd..16c82c8 100644
--- a/ui/src/app/core-ui/image/image-labeling/image-labeling.component.ts
+++ b/ui/src/app/core-ui/image/image-labeling/image-labeling.component.ts
@@ -46,13 +46,13 @@ export class ImageLabelingComponent implements OnInit {
public _imagesRoutes
@Input()
set imagesRoutes(routes) {
- this.getCocoFiles(routes);
this._imagesRoutes = routes;
+ this.getCocoFile(this._imagesRoutes, 0);
}
public imagesIndex = 0;
- public cocoFiles: CocoFormat[] = [];
+ public cocoFile: CocoFormat;
public isHoverComponent;
public brushSize: number;
@@ -70,33 +70,29 @@ export class ImageLabelingComponent implements OnInit {
this.isHoverComponent = false;
this.brushSize = 5;
this.labels = this.restService.getLabels();
- this.getCocoFiles(this._imagesRoutes);
}
handleImageIndexChange(index) {
- this.save(index);
- this.imagesIndex = index;
+ this.save(this.imagesIndex);
+ this.getCocoFile(this._imagesRoutes, index);
}
- getCocoFiles(routes) {
- this.cocoFiles = [];
- routes.forEach(route => {
+ getCocoFile(routes, index) {
// This is relevant for coco
- this.restService.getCocoFileForImage(route).subscribe(
+ this.restService.getCocoFileForImage(routes[index]).subscribe(
coco => {
if (coco === null) {
const cocoFile = new CocoFormat();
- this.cocoFormatService.addImage(cocoFile, (route));
- this.cocoFiles.push(cocoFile);
+ this.cocoFormatService.addImage(cocoFile, (routes[index]));
+ this.cocoFile = cocoFile;
} else {
- this.cocoFiles.push(coco as CocoFormat);
+ this.cocoFile = coco as CocoFormat;
}
+ this.imagesIndex = index;
}
);
- });
}
-
/* sp-image-view handler */
handleMouseDownLeft(layer: Konva.Layer, shift: ICoordinates, position: ICoordinates) {
if (this.labelingEnabled()) {
@@ -140,7 +136,7 @@ export class ImageLabelingComponent implements OnInit {
switch (this.labelingMode.getMode()) {
case LabelingMode.ReactLabeling: {
const result = this.reactLabelingService.endLabeling(position);
- const coco = this.cocoFiles[this.imagesIndex];
+ const coco = this.cocoFile;
const annotation = this.cocoFormatService.addReactAnnotationToFirstImage(coco, result[0], result[1],
this.selectedLabel.category, this.selectedLabel.label);
this.reactLabelingService.draw(annotationLayer, shift, annotation, this.imageView);
@@ -152,7 +148,7 @@ export class ImageLabelingComponent implements OnInit {
break;
case LabelingMode.BrushLabeling: {
const result = this.brushLabelingService.endLabeling(position);
- const coco = this.cocoFiles[this.imagesIndex];
+ const coco = this.cocoFile;
const annotation = this.cocoFormatService.addBrushAnnotationFirstImage(coco, result[0], result[1],
this.selectedLabel.category, this.selectedLabel.label);
this.brushLabelingService.draw(annotationLayer, shift, annotation, this.imageView);
@@ -171,7 +167,7 @@ export class ImageLabelingComponent implements OnInit {
switch (this.labelingMode.getMode()) {
case LabelingMode.PolygonLabeling:
const points = this.polygonLabelingService.endLabeling(position);
- const coco = this.cocoFiles[this.imagesIndex];
+ const coco = this.cocoFile;
const annotation = this.cocoFormatService.addPolygonAnnotationFirstImage(coco, points,
this.selectedLabel.category, this.selectedLabel.label);
this.polygonLabelingService.draw(layer, shift, annotation, this.imageView);
@@ -180,7 +176,7 @@ export class ImageLabelingComponent implements OnInit {
}
handleChildRedraw(layer: Konva.Layer, shift: ICoordinates) {
- const coco = this.cocoFiles[this.imagesIndex];
+ const coco = this.cocoFile;
if (coco !== undefined) {
for (const annotation of coco.annotations) {
annotation.isHovered = false;
@@ -198,7 +194,7 @@ export class ImageLabelingComponent implements OnInit {
handleImageViewShortCuts(key) {
if (key === 'delete') {
- const coco = this.cocoFiles[this.imagesIndex];
+ const coco = this.cocoFile;
const toDelete = coco.annotations.filter(anno => anno.isSelected);
for (const anno of toDelete) {
this.handleDeleteAnnotation(anno);
@@ -219,7 +215,7 @@ export class ImageLabelingComponent implements OnInit {
/* sp-image-annotations handlers */
handleChangeAnnotationLabel(change: [Annotation, string, string]) {
if (!this.isDrawing) {
- const coco = this.cocoFiles[this.imagesIndex];
+ const coco = this.cocoFile;
const categoryId = this.cocoFormatService.getLabelId(coco, change[1], change[2]);
change[0].category_id = categoryId;
change[0].category_name = change[2];
@@ -230,7 +226,7 @@ export class ImageLabelingComponent implements OnInit {
handleDeleteAnnotation(annotation) {
if (!this.isDrawing) {
if (annotation !== undefined) {
- const coco = this.cocoFiles[this.imagesIndex];
+ const coco = this.cocoFile;
this.cocoFormatService.removeAnnotation(coco, annotation.id);
this.imageView.redrawAll();
}
@@ -240,7 +236,7 @@ export class ImageLabelingComponent implements OnInit {
/* utils */
private labelingEnabled() {
- const coco = this.cocoFiles[this.imagesIndex];
+ const coco = this.cocoFile;
const annotation = coco.annotations.find(anno => anno.isHovered && anno.isSelected);
if (annotation !== undefined) {
return false;
@@ -250,7 +246,7 @@ export class ImageLabelingComponent implements OnInit {
}
save(imageIndex) {
- const coco = this.cocoFiles[imageIndex];
+ const coco = this.cocoFile;
if (coco !== undefined) {
const imageRoute = this._imagesRoutes[imageIndex];
this.restService.saveCocoFileForImage(imageRoute, JSON.stringify(coco)).subscribe(