Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Salamander - API
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Herman Andersen Dyrkorn
Salamander - API
Commits
04f28c93
Commit
04f28c93
authored
3 years ago
by
AndersLan
Browse files
Options
Downloads
Patches
Plain Diff
Added set size downscaling
parent
9afa0c18
No related branches found
No related tags found
1 merge request
!44
Resolve "downscale images when returning from server"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/endpoints/salamander.py
+22
-1
22 additions, 1 deletion
api/endpoints/salamander.py
api/endpoints/salamanderimageid.py
+30
-0
30 additions, 0 deletions
api/endpoints/salamanderimageid.py
with
52 additions
and
1 deletion
api/endpoints/salamander.py
+
22
−
1
View file @
04f28c93
...
@@ -6,6 +6,8 @@ from api.models.dbmodels import Location, User, Salamander
...
@@ -6,6 +6,8 @@ from api.models.dbmodels import Location, User, Salamander
import
os
import
os
import
cv2
import
cv2
import
glob
import
glob
import
cv2
import
base64
from
image_encoder.image_encoder
import
*
from
image_encoder.image_encoder
import
*
from
path_constants
import
_ACCESS_DATABASE
from
path_constants
import
_ACCESS_DATABASE
...
@@ -43,8 +45,27 @@ class SalamanderEndpoint(Resource):
...
@@ -43,8 +45,27 @@ class SalamanderEndpoint(Resource):
encoded
=
base64
.
b64encode
(
cv2
.
imencode
(
"
.jpg
"
,
resized
)[
1
]).
decode
()
encoded
=
base64
.
b64encode
(
cv2
.
imencode
(
"
.jpg
"
,
resized
)[
1
]).
decode
()
#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)
image_id
=
os
.
path
.
basename
(
path
)[
0
]
image_id
=
os
.
path
.
basename
(
path
)[
0
]
image_data
=
{
"
id
"
:
image_id
,
"
url
"
:
"
data:image/png;base64,
"
+
encoded
}
image_data
=
{
"
id
"
:
image_id
,
"
url
"
:
"
data:image/png;base64,
"
+
encoded
}
#Decode her om bestemt størrelse skal brukes
salamander_images
.
append
(
image_data
)
salamander_images
.
append
(
image_data
)
salamander_images
.
sort
(
key
=
lambda
x
:
x
.
get
(
'
id
'
))
salamander_images
.
sort
(
key
=
lambda
x
:
x
.
get
(
'
id
'
))
...
...
This diff is collapsed.
Click to expand it.
api/endpoints/salamanderimageid.py
+
30
−
0
View file @
04f28c93
...
@@ -7,6 +7,8 @@ from api import db, limiter
...
@@ -7,6 +7,8 @@ from api import db, limiter
from
api.models.dbmodels
import
Location
,
User
,
Salamander
,
SalamanderGrowth
from
api.models.dbmodels
import
Location
,
User
,
Salamander
,
SalamanderGrowth
import
os
import
os
import
glob
import
glob
import
cv2
import
sys
from
image_encoder.image_encoder
import
*
from
image_encoder.image_encoder
import
*
from
path_constants
import
_ACCESS_DATABASE
from
path_constants
import
_ACCESS_DATABASE
import
cv2
import
cv2
...
@@ -50,6 +52,34 @@ class SalamanderImageEndpoint(Resource):
...
@@ -50,6 +52,34 @@ class SalamanderImageEndpoint(Resource):
encoded
=
base64
.
b64encode
(
cv2
.
imencode
(
"
.jpg
"
,
resized
)[
1
]).
decode
()
encoded
=
base64
.
b64encode
(
cv2
.
imencode
(
"
.jpg
"
,
resized
)[
1
]).
decode
()
image_data
=
{
"
url
"
:
"
data:image/png;base64,
"
+
encoded
}
image_data
=
{
"
url
"
:
"
data:image/png;base64,
"
+
encoded
}
#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()}
salamander_images
.
append
(
image_data
)
salamander_images
.
append
(
image_data
)
return
jsonify
({
"
images
"
:
salamander_images
,
"
length
"
:
salamander_growth
.
length
,
return
jsonify
({
"
images
"
:
salamander_images
,
"
length
"
:
salamander_growth
.
length
,
...
...
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