diff --git a/.gitignore b/.gitignore
index e97a062..36f119f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,8 +2,8 @@
.vscode/
*.swp
-uploads/*
-!uploads/.gitkeep
+static/*
+!static/.gitkeep
# Byte-compiled / optimized / DLL files
__pycache__/
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..7681449
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,12 @@
+SHELL = /bin/bash
+.DEFAULT_GOAL := serve
+
+serve:
+ gunicorn flask_frontend:app
+
+dev:
+ gunicorn flask_frontend:app --reload
+
+clean:
+ rm -rf static/*
+ touch static/.gitkeep
diff --git a/examples/base64_test.py b/examples/base64_test.py
new file mode 100644
index 0000000..bfdf1db
--- /dev/null
+++ b/examples/base64_test.py
@@ -0,0 +1,8 @@
+import base64
+import cv2 as cv
+
+img = cv.imread('01-0001-cropped.png')
+
+print(img[0:100])
+
+# print(base64.b64encode(img).decode()[0:5_000])
diff --git a/flask_frontend.py b/flask_frontend.py
index 878a126..cacba2c 100644
--- a/flask_frontend.py
+++ b/flask_frontend.py
@@ -1,9 +1,19 @@
from flask import Flask, render_template, request
+from werkzeug.utils import secure_filename
import numpy as np
from ratio_pyrometry import ratio_pyrometry_pipeline
import base64
+import random
+import cv2 as cv
-app = Flask(__name__)
+app = Flask(
+ __name__,
+ static_folder='./static',
+ static_url_path='/s/'
+)
+
+app.config['STATIC_FOLDER'] = './static'
+app.config['STATIC_URL_PATH'] = '/s'
@app.route('/', methods=['GET'])
def index():
@@ -12,6 +22,8 @@ def index():
@app.route('/ratio_pyro', methods=['POST'])
def ratio_pyro():
f = request.files['file']
+ f_name = f.filename.split('.')[0]
+ f_ext = f.filename.split('.')[1]
f_bytes = np.fromstring(f.read(), np.uint8)
img_orig, img_res, key = ratio_pyrometry_pipeline(
f_bytes,
@@ -23,12 +35,23 @@ def ratio_pyro():
MIN_TEMP=float(request.form['min_temp'])
)
- img_orig_bytes = base64.urlsafe_b64encode(img_orig)
- img_res_bytes = base64.urlsafe_b64encode(img_res)
+ # img_orig_b64 = base64.b64encode(img_orig).decode()
+ # img_res_b64 = base64.b64encode(img_res).decode()
+
+ img_orig_fname = secure_filename(f'{f_name}.{f_ext}')
+ img_res_fname = secure_filename(f'{f_name}-{hex(int(random.random() * 10000000000000000000))}.{f_ext}')
+
+ cv.imwrite(f'{app.config["STATIC_FOLDER"]}/{img_orig_fname}', img_orig)
+ cv.imwrite(f'{app.config["STATIC_FOLDER"]}/{img_res_fname}', img_res)
+
+ img_orig_path = f'{app.config["STATIC_URL_PATH"]}/{img_orig_fname}'
+ img_res_path = f'{app.config["STATIC_URL_PATH"]}/{img_res_fname}'
return render_template(
'results.jinja2',
- img_orig_bytes=img_orig_bytes,
- img_res_bytes=img_res_bytes,
+ img_orig_path=img_orig_path,
+ img_res_path=img_res_path,
+ # img_orig_b64=img_orig_b64,
+ # img_res_b64=img_res_b64,
legend=key
)
diff --git a/ratio_pyrometry.py b/ratio_pyrometry.py
index 720b0ab..efa242a 100644
--- a/ratio_pyrometry.py
+++ b/ratio_pyrometry.py
@@ -32,7 +32,7 @@ def rg_ratio_normalize(
tmin = MAX_TEMP
tmax = 0
- imgnew = imgarr
+ imgnew = imgarr.copy()
for i in range(len(imgarr)):
for j in range(len(imgarr[i])):
px = imgarr[i][j]
@@ -122,7 +122,7 @@ def ratio_pyrometry_pipeline(
for i in range(key_entries):
res_temp = tmin + (i * step)
res_color = (tmax - (i * step)) / MAX_TEMP * 255
- temps.append(res_temp)
+ temps.append(math.floor(res_temp))
key_img_arr[0].append([res_color, res_color, res_color])
key_img = np.array(key_img_arr).astype(np.uint8)
diff --git a/uploads/.gitkeep b/static/.gitkeep
similarity index 100%
rename from uploads/.gitkeep
rename to static/.gitkeep
diff --git a/templates/results.jinja2 b/templates/results.jinja2
index a3ac0e6..e88f0d4 100644
--- a/templates/results.jinja2
+++ b/templates/results.jinja2
@@ -8,49 +8,53 @@
{# Original image #}
-
-
+ |
+ {# #}
+
|
-
{# Result image #}
-
-
+ |
+ {# #}
+
|
-
-
-{{ img_orig_bytes }}
-
-
-
-
+ {# Legend #}
- Color |
- Temperature |
+ |
+
+
+
+ Color |
+ Temperature |
+
+ {% for temp, color in legend.items() %}
+
+ |
+ {{ temp }}°C |
+
+ {% endfor %}
+
+
+ |
- {% for temp, color in legend.items() %}
-
- |
- {{ temp }}°C |
-
- {% endfor %}