-
Notifications
You must be signed in to change notification settings - Fork 18
Resolve LabelBOT for tiled images #1232 #1313
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
base: master
Are you sure you want to change the base?
Conversation
|
@mzur Dann geht zwar meine History (5 commits -> 1 commit) verloren, aber das ist nicht so schlimm denke ich. Passt das so? Dann mach ich das morgen und dann kann die PR auch reviewed werden. |
|
Ja das passt so, kein Problem 👍 |
|
btw this is our commit message style guide in case you are interested: https://chris.beams.io/git-commit |
Since tiled images are transmitted in parts, no underlying image can be directly accessed. Instead, a screenshot of the map is taken and cropped according to the selection.
|
@mzur I changed the PR to ready for review, but can't select a reviewer or request a review. It's ready though. |
|
Please resolve the linter errors. Run it locally with |
|
I resolved them, but the pipeline doesn't seem to run automatically @mzur |
mzur
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works great already! My comments are mostly about stylistic issues.
resources/assets/js/annotations/components/annotationCanvas/labelBot.vue
Outdated
Show resolved
Hide resolved
resources/assets/js/annotations/components/annotationCanvas/labelBot.vue
Outdated
Show resolved
Hide resolved
resources/assets/js/annotations/components/annotationCanvas/labelBot.vue
Outdated
Show resolved
Hide resolved
resources/assets/js/annotations/components/annotationCanvas/labelBot.vue
Outdated
Show resolved
Hide resolved
resources/assets/js/annotations/components/annotationCanvas/labelBot.vue
Outdated
Show resolved
Hide resolved
resources/assets/js/annotations/components/annotationCanvas/labelBot.vue
Show resolved
Hide resolved
resources/assets/js/annotations/components/annotationCanvas.vue
Outdated
Show resolved
Hide resolved
Removed unneeded constructs for the labelbot images (TILEDIMAGES state, tempCanvas, etc.)
|
I made the changes as requested @mzur, ready for review again. |
mzur
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've merged the current master.
I noticed that there was a slight delay when the labelbotImage is generated. I suggested some optimizations below.
| if(!this.image.tiled) | ||
| return this.createLabelbotImageFromRegularImage(points); | ||
| else | ||
| return await this.createLabelbotImageFromTiledImage(points); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if(!this.image.tiled) | |
| return this.createLabelbotImageFromRegularImage(points); | |
| else | |
| return await this.createLabelbotImageFromTiledImage(points); | |
| if (!this.image.tiled) { | |
| return this.createLabelbotImageFromRegularImage(points); | |
| } else { | |
| return await this.createLabelbotImageFromTiledImage(points); | |
| } |
| [0, 0, image.width, image.height] | ||
| ); | ||
| if(width === 0 || height === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if(width === 0 || height === 0) { | |
| if (width === 0 || height === 0) { |
| return [left, top, Math.max(0, right - left), Math.max(0, bottom - top)]; | ||
| }, | ||
| getScaledImageSelection(image, x, y, width, height) { | ||
| if(!this.tempCanvas) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if(!this.tempCanvas) { | |
| if (!this.tempCanvas) { |
| if(this.labelbotIsActive) | ||
| { | ||
| try { | ||
| labelbotImage = await this.createLabelbotImage(points); | ||
| } | ||
| catch(error) { | ||
| this.annotationSource.removeFeature(e.feature); | ||
| Messages.danger(error.message); | ||
| return; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if(this.labelbotIsActive) | |
| { | |
| try { | |
| labelbotImage = await this.createLabelbotImage(points); | |
| } | |
| catch(error) { | |
| this.annotationSource.removeFeature(e.feature); | |
| Messages.danger(error.message); | |
| return; | |
| } | |
| } | |
| if (this.labelbotIsActive) { | |
| try { | |
| labelbotImage = await this.createLabelbotImage(points); | |
| } catch(error) { | |
| this.annotationSource.removeFeature(e.feature); | |
| Messages.danger(error.message); | |
| return; | |
| } | |
| } |
| .finally((annotation) => { | ||
| this.labelbotRequestsInFlight -= 1; | ||
| if(this.labelbotRequestsInFlight > 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| if(this.labelbotRequestsInFlight > 0) { | |
| if (this.labelbotRequestsInFlight > 0) { |
| makeBlob(event.context.canvas).then(blob => { | ||
| resolve(createImageBitmap(blob)); | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
makeBlob and createImageBitmap are quite slow (600-700 ms on my machine). We don't need a blob or an ImageBitmap object, though, and can use the trimmed canvas directly (200 ms on my machine):
| makeBlob(event.context.canvas).then(blob => { | |
| resolve(createImageBitmap(blob)); | |
| }); | |
| resolve(trimCanvas(event.context.canvas)); |
makeBlob can be moved back to the screenshotButton then.
Most of the remaining 200 ms was used by trimCanvas. This can be improved with an early return (see below).
| } | ||
|
|
||
| function trimCanvas(canvas) { | ||
| let ctx = canvas.getContext('2d'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Early return:
| let ctx = canvas.getContext('2d'); | |
| let ctx = canvas.getContext('2d'); | |
| let topLeft = ctx.getImageData(0, 0, 1, 1); | |
| let bottomRight = ctx.getImageData(canvas.width - 1, canvas.height - 1, 1, 1); | |
| if (topLeft.data[3] !== 0 && bottomRight.data[3] !== 0) { | |
| return canvas; | |
| } |
Resolves Issue #1232 by taking a screenshot of the map if the image is tiled.