Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Herman Andersen Dyrkorn
Salamander - API
Commits
6d253a0e
Commit
6d253a0e
authored
Jun 09, 2021
by
AndersLan
Browse files
removed percentage scaling
parent
04f28c93
Changes
2
Hide whitespace changes
Inline
Side-by-side
api/endpoints/salamander.py
View file @
6d253a0e
...
...
@@ -34,38 +34,27 @@ class SalamanderEndpoint(Resource):
image
=
cv2
.
imread
(
path
)
# percent of original size
scale_percent
=
40
width
=
int
(
image
.
shape
[
1
]
*
scale_percent
/
100
)
height
=
int
(
image
.
shape
[
0
]
*
scale_percent
/
100
)
dim
=
(
width
,
height
)
#scaling to set size
height
,
width
,
_
=
image
.
shape
# re
si
z
e
image
resized
=
cv2
.
resize
(
image
,
dim
,
interpolation
=
cv2
.
INTER_AREA
)
desired_long_
si
d
e
=
320
scaling_factor
=
1
encoded
=
base64
.
b64encode
(
cv2
.
imencode
(
".jpg"
,
resized
)[
1
]).
decode
()
if
width
>
height
:
scaling_factor
=
desired_long_side
/
width
else
:
scaling_factor
=
desired_long_side
/
height
#scaling to set size
# height, width, _ = image.shape
#
# desired_long_side = 150
# scaling_factor = 1
#
# if width > height:
# scaling_factor = desired_long_side / width
# else:
# scaling_factor = desired_long_side / height
#
# new_dim = (int(width * scaling_factor), int(height * scaling_factor))
#
# # resize image
# image = cv2.resize(image, new_dim, interpolation=cv2.INTER_AREA)
#
# _, buffer = cv2.imencode('.jpg', image)
# encoded = base64.b64encode(buffer)
new_dim
=
(
int
(
width
*
scaling_factor
),
int
(
height
*
scaling_factor
))
# resize image
image
=
cv2
.
resize
(
image
,
new_dim
,
interpolation
=
cv2
.
INTER_AREA
)
_
,
buffer
=
cv2
.
imencode
(
'.jpg'
,
image
)
encoded
=
base64
.
b64encode
(
buffer
)
image_id
=
os
.
path
.
basename
(
path
)[
0
]
image_data
=
{
"id"
:
image_id
,
"url"
:
"data:image/png;base64,"
+
encoded
}
#D
ecode
her om bestemt størrelse skal brukes
image_data
=
{
"id"
:
image_id
,
"url"
:
"data:image/png;base64,"
+
encoded
.
d
ecode
()}
salamander_images
.
append
(
image_data
)
salamander_images
.
sort
(
key
=
lambda
x
:
x
.
get
(
'id'
))
...
...
api/endpoints/salamanderimageid.py
View file @
6d253a0e
...
...
@@ -39,46 +39,29 @@ class SalamanderImageEndpoint(Resource):
if
basename
.
__contains__
(
str
(
image_id
)):
image
=
cv2
.
imread
(
path
)
if
not
basename
.
__contains__
(
"str"
):
#Scale only original to set size
# percent of original size
scale_percent
=
20
width
=
int
(
image
.
shape
[
1
]
*
scale_percent
/
100
)
height
=
int
(
image
.
shape
[
0
]
*
scale_percent
/
100
)
dim
=
(
width
,
height
)
height
,
width
,
_
=
image
.
shape
print
(
sys
.
getsizeof
(
image
))
# re
si
z
e
image
resized
=
cv2
.
resize
(
image
,
dim
,
interpolation
=
cv2
.
INTER_AREA
)
desired_long_
si
d
e
=
320
scaling_factor
=
1
encoded
=
base64
.
b64encode
(
cv2
.
imencode
(
".jpg"
,
resized
)[
1
]).
decode
()
if
width
>
height
:
scaling_factor
=
desired_long_side
/
width
else
:
scaling_factor
=
desired_long_side
/
height
image_data
=
{
"url"
:
"data:image/png;base64,"
+
encoded
}
new_dim
=
(
int
(
width
*
scaling_factor
),
int
(
height
*
scaling_factor
))
#Scale only original to set size
# image = cv2.imread(path)
# if not basename.__contains__("str"):
#
# height, width, _ = image.shape
# print(sys.getsizeof(image))
#
# desired_long_side = 320
# scaling_factor = 1
#
# if width > height:
# scaling_factor = desired_long_side/width
# else:
# scaling_factor = desired_long_side/height
#
# new_dim = (int(width*scaling_factor), int(height*scaling_factor))
#
# # resize image
# image = cv2.resize(image, new_dim, interpolation=cv2.INTER_AREA)
# print(sys.getsizeof(image))
#
# _, buffer = cv2.imencode('.jpg', image)
# encoded = base64.b64encode(buffer)
#
# #encoded = encode(path)[2:-1]
# image_data = {"url": "data:image/png;base64," + encoded.decode()}
# resize image
image
=
cv2
.
resize
(
image
,
new_dim
,
interpolation
=
cv2
.
INTER_AREA
)
print
(
sys
.
getsizeof
(
image
))
_
,
buffer
=
cv2
.
imencode
(
'.jpg'
,
image
)
encoded
=
base64
.
b64encode
(
buffer
)
image_data
=
{
"url"
:
"data:image/png;base64,"
+
encoded
.
decode
()}
salamander_images
.
append
(
image_data
)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment