Skip to content

Commit

Permalink
Select source image from mapbox; Redirection improved and accelerate …
Browse files Browse the repository at this point in the history
…changing functions; wrong size of OC result image debugged;
  • Loading branch information
TwSphinx54 committed Jun 26, 2022
1 parent 6088abe commit 8e20529
Show file tree
Hide file tree
Showing 9 changed files with 885 additions and 147 deletions.
4 changes: 1 addition & 3 deletions functions/object_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def object_classification(img_path, predictor):
lut[3] = [0, 222, 255]
lut[4] = [0, 0, 0]
res_img = lut[label_map]
# res_img = cv.resize(res_img, (1024, 1024), interpolation=cv.INTER_LINEAR)

# 拆分图像
# type0道路, type1树木, type2人造用地, type3空地
Expand All @@ -85,12 +84,11 @@ def object_classification(img_path, predictor):
Kappa = 0.41
'''
scores = [0, 0, 0, 0]
areas=[0,0,0,0]
areas = [0, 0, 0, 0]
for num in range(4):
types[num] = add_alpha(types[num])
scores[num] = sum(map(sum, score_map[types[num][:, :, 3] == 255])) / (
len(score_map[types[num][:, :, 3] == 255]) + 1)
areas[num] = len(types[num][types[num][:, :, 3] == 255])
types[num] = cv.resize(types[num], (1024, 1024), interpolation=cv.INTER_LINEAR)

return res_img, types, scores, period, areas
68 changes: 37 additions & 31 deletions process.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import math
import os
from flask import Flask, flash, request, redirect, url_for, render_template
from werkzeug.utils import secure_filename
from urllib.request import urlretrieve
from functions.object_detection import load_object_detection, object_detection
from functions.object_classification import load_object_classification, object_classification
from functions.object_extraction import load_object_extraction, object_extraction
Expand All @@ -18,6 +18,8 @@
pro, model, loc, score, period, shape, areas = [0] * 7


# animation = True

def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS

Expand All @@ -29,7 +31,8 @@ def clip_img(img, coord):
@app.route('/welcome', methods=['GET', 'POST'])
def welcome():
if request.method == 'GET':
return render_template('welcome.html')
animation = request.args.get('animation')
return render_template('welcome.html', animation=animation)
elif request.method == 'POST':
global pro, model
pro = request.values['pro']
Expand All @@ -51,37 +54,38 @@ def upload_file():
if request.method == 'GET':
return render_template('index.html', pro=pro)
elif request.method == 'POST':
if pro == '1':
file1 = request.files['image1']
file2 = request.files['image2']
# If the user does not select a file, the browser submits an empty file without a filename.
if (file1.filename == '') | (file2.filename == ''):
flash('No selected file')
return redirect(request.url)
if file1 and allowed_file(file1.filename) and file2 and allowed_file(file2.filename):
filename1 = 'A.png'
filename2 = 'B.png'
A = os.path.join(app.config['UPLOAD_FOLDER'], filename1)
B = os.path.join(app.config['UPLOAD_FOLDER'], filename2)
file1.save(A)
file2.save(B)
res, alpha, score, period = change_detection(A, B, model)
shape = list(res.shape)
cv.imwrite(UPLOAD_FOLDER + '/result.png', res)
cv.imwrite(UPLOAD_FOLDER + '/change.png', alpha)
print(period)
return redirect(url_for('main_process'))
status = request.values['status']
if status == 'change':
return redirect(url_for('welcome', animation=False))
else:
file = request.files['image']
# If the user does not select a file, the browser submits an empty file without a filename.
if file.filename == '':
flash('No selected file')
return redirect(request.url)
if file and allowed_file(file.filename):
# filename = secure_filename(file.filename)
if pro == '1':
file1 = request.files['image1']
file2 = request.files['image2']
# If the user does not select a file, the browser submits an empty file without a filename.
if (file1.filename == '') | (file2.filename == ''):
flash('No selected file')
return redirect(request.url)
if file1 and allowed_file(file1.filename) and file2 and allowed_file(file2.filename):
filename1 = 'A.png'
filename2 = 'B.png'
A = os.path.join(app.config['UPLOAD_FOLDER'], filename1)
B = os.path.join(app.config['UPLOAD_FOLDER'], filename2)
file1.save(A)
file2.save(B)
res, alpha, score, period = change_detection(A, B, model)
shape = list(res.shape)
cv.imwrite(UPLOAD_FOLDER + '/result.png', res)
cv.imwrite(UPLOAD_FOLDER + '/change.png', alpha)
print(period)
return redirect(url_for('main_process'))
else:
filename = 'origin.png'
save_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
file.save(save_path)
if status == 'select':
urlretrieve(request.values['img_url'], save_path)
else:
file = request.files['image']
file.save(save_path)
if pro == '0':
res, roads, score, period, mixed = object_extraction(save_path, model)
shape = list(res.shape)
Expand Down Expand Up @@ -114,7 +118,9 @@ def main_process():
return render_template('main.html', pro=pro, ele=[score, period, shape])
elif request.method == 'POST':
status = request.values['status']
if status == 'clip':
if status == 'change':
return redirect(url_for('welcome', animation=False))
elif status == 'clip':
coord = [request.values['x0'], request.values['y0'], request.values['x1'], request.values['y1']]
coord = [math.floor(float(k)) for k in coord]
img = cv.imread(UPLOAD_FOLDER + '/origin.png')
Expand Down
Binary file added webpage/imgs/button_bg.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 8e20529

Please sign in to comment.