-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
101 lines (72 loc) · 2.65 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import threading
from flask import Flask, request, render_template, jsonify, Blueprint
import json # Python標準のJSONライブラリを読み込んで、データの保存等に使用する
from model.watch_dir import start_watchdog
from get_imgs_filepath import get_images_filepath
from get_imgs_filepath import get_filenames
app = Flask(__name__)
app.config["JSON_AS_ASCII"] = False # 日本語などのASCII以外の文字列を返したい場合は、こちらを設定しておく
# 静的ディレクトリの追加
add_app = Blueprint("image", __name__,
static_url_path="/image", static_folder="./image")
app.register_blueprint(add_app)
# ディレクトリの監視を並列で開始
directory_to_watch = "./image/input" # 保存先
thread = threading.Thread(target=start_watchdog, args=(directory_to_watch,))
thread.daemon = True # メインスレッドが終了したら、スレッドも終了する
thread.start()
# http://127.0.0.1:5000/
@app.route('/')
def index():
# このコードは上に書いたほうが良い気がする (変更済み)
# # ディレクトリの監視を並列で開始
# directory_to_watch = "./image/input" # 保存先
# thread = threading.Thread(target=start_watchdog, args=(directory_to_watch,))
# thread.start()
return render_template("index.html")
@app.route('/upload', methods=['POST'])
def upload():
try:
# 画像dataの取得
data = request.files.get('data') # TODO
# image/inputに保存
data.save('image/input/' + data.filename)
# TODO: 画像の処理
except Exception as e:
print(e)
return jsonify({
"error": "画像の保存に失敗しました。"
})
return jsonify({
"success": "画像の保存に成功しました。"
})
@app.route('/fetch_files_path', methods = ['POST'])
def fetch_files_path():
directory = request.form['directory']
files_path = get_images_filepath(directory)
return jsonify({
"files_path": files_path
})
# モザイク
@app.route('/mosaic')
def mosaic():
return render_template("mosaic.html")
# 枠で囲む
@app.route('/frame')
def frame():
return render_template("frame.html")
# 輪郭抽出
@app.route('/contour')
def contour():
return render_template("contour.html")
# グレイスケール
@app.route('/grayscale')
def grayscale():
return render_template("grayscale.html")
# 物体検出
@app.route('/detection')
def detection():
return render_template("detection.html")
if __name__ == "__main__":
# debugモードが不要の場合は、debug=Trueを消してください
app.run(debug=True)