Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
Base Worker
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Workers
Base Worker
Commits
4dae26b6
Commit
4dae26b6
authored
3 years ago
by
Bastien Abadie
Browse files
Options
Downloads
Patches
Plain Diff
Support bounding box for elements using cache
parent
f53d7baf
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!111
Support bounding box for elements using cache
Pipeline
#78565
passed
3 years ago
Stage: test
Stage: build
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
arkindex_worker/cache.py
+14
-5
14 additions, 5 deletions
arkindex_worker/cache.py
tests/test_cache.py
+6
-4
6 additions, 4 deletions
tests/test_cache.py
with
20 additions
and
9 deletions
arkindex_worker/cache.py
+
14
−
5
View file @
4dae26b6
...
...
@@ -72,19 +72,28 @@ class CachedElement(Model):
"""
if
not
self
.
image_id
or
not
self
.
polygon
:
raise
ValueError
(
f
"
Element
{
self
.
id
}
has no image
"
)
# Always fetch the image from the bounding box when size differs from full image
bounding_box
=
polygon_bounding_box
(
self
.
polygon
)
if
(
bounding_box
.
width
!=
self
.
image
.
width
or
bounding_box
.
height
!=
self
.
image
.
height
):
box
=
f
"
{
bounding_box
.
x
}
,
{
bounding_box
.
y
}
,
{
bounding_box
.
x
+
bounding_box
.
width
}
,
{
bounding_box
.
y
+
bounding_box
.
height
}
"
else
:
box
=
"
full
"
if
max_size
is
None
:
resize
=
"
full
"
else
:
bounding_box
=
polygon_bounding_box
(
self
.
polygon
)
# Do not resize for polygons that do not exactly match the images
# as the resize is made directly by the IIIF server using the box parameter
if
(
bounding_box
.
width
!=
self
.
image
.
width
or
bounding_box
.
height
!=
self
.
image
.
height
):
resize
=
"
full
"
logger
.
warning
(
"
Only full size elements covered, downloading full size image
"
)
# Do not resize when the image is below the maximum size
elif
self
.
image
.
width
<=
max_size
and
self
.
image
.
height
<=
max_size
:
resize
=
"
full
"
...
...
@@ -99,7 +108,7 @@ class CachedElement(Model):
if
not
url
.
endswith
(
"
/
"
):
url
+=
"
/
"
return
open_image
(
f
"
{
url
}
full
/
{
resize
}
/0/default.jpg
"
,
*
args
,
**
kwargs
)
return
open_image
(
f
"
{
url
}
{
box
}
/
{
resize
}
/0/default.jpg
"
,
*
args
,
**
kwargs
)
class
CachedTranscription
(
Model
):
...
...
This diff is collapsed.
Click to expand it.
tests/test_cache.py
+
6
−
4
View file @
4dae26b6
...
...
@@ -78,13 +78,15 @@ CREATE TABLE "transcriptions" ("id" TEXT NOT NULL PRIMARY KEY, "element_id" TEXT
[
# No max_size: no resize
(
400
,
600
,
400
,
600
,
None
,
"
http://something/full/full/0/default.jpg
"
),
# No max_size: resize on bbox
(
400
,
600
,
200
,
100
,
None
,
"
http://something/0,0,200,100/full/0/default.jpg
"
),
# max_size equal to the image size, no resize
(
400
,
600
,
400
,
600
,
600
,
"
http://something/full/full/0/default.jpg
"
),
(
600
,
400
,
600
,
400
,
600
,
"
http://something/full/full/0/default.jpg
"
),
(
400
,
400
,
400
,
400
,
400
,
"
http://something/full/full/0/default.jpg
"
),
# max_size is smaller than the image, resize
(
400
,
600
,
400
,
600
,
400
,
"
http://something/full/266,400/0/default.jpg
"
),
(
400
,
600
,
200
,
600
,
400
,
"
http://something/
full/266,400
/0/default.jpg
"
),
(
400
,
600
,
200
,
600
,
400
,
"
http://something/
0,0,200,600/full
/0/default.jpg
"
),
(
600
,
400
,
600
,
400
,
400
,
"
http://something/full/400,266/0/default.jpg
"
),
(
400
,
400
,
400
,
400
,
200
,
"
http://something/full/200,200/0/default.jpg
"
),
# max_size above the image size, no resize
...
...
@@ -118,9 +120,9 @@ def test_element_open_image(
image
=
image
,
polygon
=
[
[
0
,
0
],
[
image
_width
,
0
],
[
image
_width
,
image
_height
],
[
0
,
image
_height
],
[
polygon
_width
,
0
],
[
polygon
_width
,
polygon
_height
],
[
0
,
polygon
_height
],
[
0
,
0
],
],
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment