Skip to content
Snippets Groups Projects
Commit 2408d4cf authored by Herman Andersen Dyrkorn's avatar Herman Andersen Dyrkorn
Browse files

server working with algorithm

parent 7c544713
No related branches found
No related tags found
1 merge request!21Resolve "combine matchsalamander with ai"
......@@ -9,7 +9,7 @@ from tensorflow.python.keras.layers import Minimum
import algorithm.train_src.predict_salamander_abdomen as psa
from threading import Semaphore
DEEPLABCUT_CONFIG_PATH = "./dlc_model/config.yaml"
DEEPLABCUT_CONFIG_PATH = "./algorithm/train_src/dlc_model/config.yaml"
########################################
# CONSTANTS
########################################
......@@ -29,7 +29,7 @@ STRAIGTHENED_IMAGE_ASPECT_RATIO = STRAIGTHENED_IMAGE_HEIGHT / STRAIGTHENED_IMAGE
# amount of pixels to add to the width of the shoulder including what the AI estimates:
SHOULDER_ESTIMATION_BUFFER = 15
# minimum distance between shoulder points in pixels:
MINIMUM_SHOULDER_WIDTH = 100
MINIMUM_SHOULDER_WIDTH = 50
# minimum distance between the points, 2 and 3 in pixels:
MINIMUM_MID_POINT_DISTANCE = 30
......
......@@ -2,7 +2,8 @@ from flask import request, jsonify
from flask_restful import Resource
from flask_jwt_extended import get_jwt_identity, jwt_required
from algorithm.train_src.new_straightening import straighten
import cv2
import os
ALLOWED_EXTENSIONS = ['jpeg', 'png', 'jpg']
......@@ -16,16 +17,18 @@ class FindSalamanderInfo(Resource):
return jsonify({"message": "no file given"})
image = request.files['image']
user_id = get_jwt_identity()
image.filename = str(user_id) + "." + extension(image.filename)
image.save("temp_images/" + image.filename)
execution_path = os.path.abspath(os.getcwd())
print(execution_path + "/temp_images/" + str(user_id) + "." + extension(image.filename))
img = cv2.imread(execution_path + "/temp_images/" + str(user_id) + "." + extension(image.filename), 1)
if image.filename != '':
if image and allowed_image(image.filename):
# run AI on image
str_image, _, _, _, _ = straighten(image)
if str_image:
str_image.filename = str(user_id) + "_str.png"
str_image.save("temp_images/" + str_image.filename)
str_image, _, _, _, _ = straighten(img)
if str_image is not None:
cv2.imwrite("temp_images/" + str(user_id) + "_str.png", str_image)
# store processed and original image
image.filename = str(user_id) + "." + extension(image.filename)
image.save("temp_images/" + image.filename)
return jsonify({"sex": "AI_sex", "species": "AI_species"})
else:
return jsonify({"message": "file extension not allowed"})
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment