Commit 6d253a0e authored by AndersLan's avatar AndersLan
Browse files

removed percentage scaling

parent 04f28c93
......@@ -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
# resize image
resized = cv2.resize(image, dim, interpolation=cv2.INTER_AREA)
desired_long_side = 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} #Decode her om bestemt størrelse skal brukes
image_data = {"id": image_id, "url": "data:image/png;base64," + encoded.decode()}
salamander_images.append(image_data)
salamander_images.sort(key=lambda x: x.get('id'))
......
......@@ -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))
# resize image
resized = cv2.resize(image, dim, interpolation=cv2.INTER_AREA)
desired_long_side = 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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment