|
@@ -6,10 +6,9 @@ from flask_cors import *
|
|
|
from PIL import Image
|
|
from PIL import Image
|
|
|
import base64
|
|
import base64
|
|
|
|
|
|
|
|
-from analyse_func import do_analysis
|
|
|
|
|
|
|
+from analyse_func import do_analysis
|
|
|
from classify import api_dyna
|
|
from classify import api_dyna
|
|
|
-from db_project import get_status, process_db, lookup_data, add_new_data_dyna, add_new_data, create_table_dynamic, \
|
|
|
|
|
- create_table, create_db
|
|
|
|
|
|
|
+from db_project import get_status,process_db,lookup_data ,add_new_data_dyna,add_new_data,create_table_dynamic,create_table,create_db
|
|
|
|
|
|
|
|
# str_res=""
|
|
# str_res=""
|
|
|
# a dict contains the txt
|
|
# a dict contains the txt
|
|
@@ -18,9 +17,39 @@ li_last = []
|
|
|
# store dic_data's json format
|
|
# store dic_data's json format
|
|
|
bJson = ""
|
|
bJson = ""
|
|
|
global_index = [6]
|
|
global_index = [6]
|
|
|
-global_video_index = 0
|
|
|
|
|
|
|
+global_video_index=0
|
|
|
li_return = []
|
|
li_return = []
|
|
|
img_return = []
|
|
img_return = []
|
|
|
|
|
+flag_run=False
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+##jump
|
|
|
|
|
+##result["jump_power"]["level"]/["path"]/["val"]
|
|
|
|
|
+##result["core_strength"]["level"]/["path"] 1 2 3 4
|
|
|
|
|
+##result["landing_position"]["level"]/["path"]["val"]
|
|
|
|
|
+##juanfu
|
|
|
|
|
+## result["head_power"]["level"]/["path"]/["val"]
|
|
|
|
|
+#result["core_strength"]["level"]/["path"]
|
|
|
|
|
+##result["body_stability"]["level"]/["val"]
|
|
|
|
|
+
|
|
|
|
|
+##pingban
|
|
|
|
|
+"""
|
|
|
|
|
+result["arm_strength"]["level"]/["path"]/["val"]
|
|
|
|
|
+result["stability"]["level"]/["path"]/["val"]
|
|
|
|
|
+result["standard"]["level"]/["path"]/["val"]
|
|
|
|
|
+"""
|
|
|
|
|
+##shendun
|
|
|
|
|
+"""
|
|
|
|
|
+result["leg_strength"]["level"]/["path"]
|
|
|
|
|
+"""
|
|
|
|
|
+##gaotaitui
|
|
|
|
|
+"""
|
|
|
|
|
+result["standard"]["level"]/["path"]
|
|
|
|
|
+"""
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
# read txt file and change it to the list format
|
|
# read txt file and change it to the list format
|
|
@@ -52,25 +81,25 @@ def read_pose_processes_txt_result():
|
|
|
i = i + 1 # i是头部分析那行
|
|
i = i + 1 # i是头部分析那行
|
|
|
dic_1["name"] = "头部分析"
|
|
dic_1["name"] = "头部分析"
|
|
|
dic_1["value"] = lines[i][5:len(lines[i]) - 1]
|
|
dic_1["value"] = lines[i][5:len(lines[i]) - 1]
|
|
|
- i = i + 1 # 头部数字级别
|
|
|
|
|
|
|
+ i = i + 1 # 头部数字级别
|
|
|
dic_1["level"] = int(lines[i].strip())
|
|
dic_1["level"] = int(lines[i].strip())
|
|
|
li.append(dic_1)
|
|
li.append(dic_1)
|
|
|
dic_2 = {}
|
|
dic_2 = {}
|
|
|
- i += 2 # 第六行 i=6
|
|
|
|
|
|
|
+ i += 2 #第六行 i=6
|
|
|
dic_2["name"] = "肩部分析"
|
|
dic_2["name"] = "肩部分析"
|
|
|
- # num_risk_1 = int(lines[i + 1].strip())
|
|
|
|
|
|
|
+ #num_risk_1 = int(lines[i + 1].strip())
|
|
|
dic_2["value"] = lines[i][:-1] + " " + lines[(i + 1)][:-1]
|
|
dic_2["value"] = lines[i][:-1] + " " + lines[(i + 1)][:-1]
|
|
|
num_risk_2 = int(lines[i + 2].strip())
|
|
num_risk_2 = int(lines[i + 2].strip())
|
|
|
dic_2["level"] = int(num_risk_2)
|
|
dic_2["level"] = int(num_risk_2)
|
|
|
li.append(dic_2)
|
|
li.append(dic_2)
|
|
|
- i += 4 # i=10
|
|
|
|
|
|
|
+ i += 4 #i=10
|
|
|
dic_3 = {}
|
|
dic_3 = {}
|
|
|
dic_3["name"] = "髋部分析"
|
|
dic_3["name"] = "髋部分析"
|
|
|
dic_3["value"] = lines[i][:-1] + " " + lines[(i + 1)][:-1]
|
|
dic_3["value"] = lines[i][:-1] + " " + lines[(i + 1)][:-1]
|
|
|
num_risk_1 = int(lines[i + 2].strip())
|
|
num_risk_1 = int(lines[i + 2].strip())
|
|
|
- # num_risk_2 = int(lines[i + 3].strip())
|
|
|
|
|
|
|
+ #num_risk_2 = int(lines[i + 3].strip())
|
|
|
dic_3["level"] = int(max(num_risk_1, 0))
|
|
dic_3["level"] = int(max(num_risk_1, 0))
|
|
|
- i += 4 # i=14
|
|
|
|
|
|
|
+ i += 4 #i=14
|
|
|
dic_4 = {"name": "腿型分析", "value": lines[i][:-1]}
|
|
dic_4 = {"name": "腿型分析", "value": lines[i][:-1]}
|
|
|
li.append(dic_3)
|
|
li.append(dic_3)
|
|
|
li.append(dic_4)
|
|
li.append(dic_4)
|
|
@@ -120,14 +149,12 @@ def read_pose_processes_txt_result():
|
|
|
def run_the_process(index: int = 0, height: float = 110):
|
|
def run_the_process(index: int = 0, height: float = 110):
|
|
|
# sys.path.append("../analyse_func.py")
|
|
# sys.path.append("../analyse_func.py")
|
|
|
# import analyse_func
|
|
# import analyse_func
|
|
|
- # print(global_index[0])
|
|
|
|
|
|
|
+ #print(global_index[0])
|
|
|
do_analysis(global_index[0], height)
|
|
do_analysis(global_index[0], height)
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
# 把list转化为可以直接返回的json格式
|
|
# 把list转化为可以直接返回的json格式
|
|
|
|
|
|
|
|
def list_to_json(li):
|
|
def list_to_json(li):
|
|
|
- # print(li)
|
|
|
|
|
|
|
+ #print(li)
|
|
|
|
|
|
|
|
aJson = json.dumps(li, ensure_ascii=False)
|
|
aJson = json.dumps(li, ensure_ascii=False)
|
|
|
print(aJson)
|
|
print(aJson)
|
|
@@ -138,142 +165,115 @@ def list_to_json(li):
|
|
|
# print(dict1)
|
|
# print(dict1)
|
|
|
return aJson
|
|
return aJson
|
|
|
# print(dic_data)
|
|
# print(dic_data)
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
app = Flask(__name__)
|
|
app = Flask(__name__)
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-def save_images(file):
|
|
|
|
|
|
|
+def save_file(filed):
|
|
|
base = "pose_source_images/"
|
|
base = "pose_source_images/"
|
|
|
- filename = file.filename
|
|
|
|
|
|
|
+ filename = filed.filename
|
|
|
index = global_index[0]
|
|
index = global_index[0]
|
|
|
- # global_index[0] = index
|
|
|
|
|
|
|
+ #global_index[0] = index
|
|
|
suffix = ".png"
|
|
suffix = ".png"
|
|
|
if filename.find("jpg") > 0:
|
|
if filename.find("jpg") > 0:
|
|
|
suffix = ".jpg"
|
|
suffix = ".jpg"
|
|
|
elif filename.find("png") > 0:
|
|
elif filename.find("png") > 0:
|
|
|
suffix = ".png"
|
|
suffix = ".png"
|
|
|
save_name = ""
|
|
save_name = ""
|
|
|
- print(str(index) + "index")
|
|
|
|
|
- print(filename + "filename")
|
|
|
|
|
|
|
+ print(str(index)+"index")
|
|
|
|
|
+ print(filename+"filename")
|
|
|
if "front" in filename:
|
|
if "front" in filename:
|
|
|
save_name = base + str(index) + str("-0") + suffix
|
|
save_name = base + str(index) + str("-0") + suffix
|
|
|
- print(filename + "filename_front")
|
|
|
|
|
- print(save_name + "savename_front")
|
|
|
|
|
|
|
+ print(filename+"filename_front")
|
|
|
|
|
+ print(save_name+"savename_front")
|
|
|
elif "right" in filename:
|
|
elif "right" in filename:
|
|
|
save_name = base + str(index) + str("-1") + suffix
|
|
save_name = base + str(index) + str("-1") + suffix
|
|
|
- print(filename + "filename_right")
|
|
|
|
|
- print(save_name + "savename_right")
|
|
|
|
|
- else:
|
|
|
|
|
|
|
+ print(filename+"filename_right")
|
|
|
|
|
+ print(save_name+"savename_right")
|
|
|
|
|
+ else :
|
|
|
print("nope")
|
|
print("nope")
|
|
|
- file.save(save_name)
|
|
|
|
|
|
|
+ filed.save(save_name)
|
|
|
print(filename)
|
|
print(filename)
|
|
|
print(save_name)
|
|
print(save_name)
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-# 运行动态分析的入口
|
|
|
|
|
-def run_video(mode, num, ana=1):
|
|
|
|
|
- q = "./video/" + str(num) + ".mp4"
|
|
|
|
|
- re = api_dyna(q, mode, ana)
|
|
|
|
|
|
|
+#运行动态分析的入口
|
|
|
|
|
+def run_video(mode,num,ana=1):
|
|
|
|
|
+ q="./video/"+str(num)+".mp4"
|
|
|
|
|
+ re= api_dyna(q,mode,ana)
|
|
|
|
|
+ process_db(num)
|
|
|
return re
|
|
return re
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-def lookup_video(num, ana=0):
|
|
|
|
|
- q = "./video/" + str(num) + ".mp4"
|
|
|
|
|
- mode = lookup_data(num)
|
|
|
|
|
- re = api_dyna(q, mode, ana)
|
|
|
|
|
|
|
+def lookup_video(num,ana=0):
|
|
|
|
|
+ q="./video/"+str(num)+".mp4"
|
|
|
|
|
+ mode=lookup_data(num)
|
|
|
|
|
+ re= api_dyna(q,mode,ana)
|
|
|
|
|
+ process_db(num)
|
|
|
return re
|
|
return re
|
|
|
|
|
|
|
|
-
|
|
|
|
|
###send a video and return a id marked the video (identical)
|
|
###send a video and return a id marked the video (identical)
|
|
|
-@app.route('/get videoid', methods=['POST'])
|
|
|
|
|
|
|
+@app.route('/get_videoid',methods=['POST'])
|
|
|
@cross_origin()
|
|
@cross_origin()
|
|
|
def get_videoid():
|
|
def get_videoid():
|
|
|
- dict_video_ = request.form.to_dict()
|
|
|
|
|
- dict_video_mp4 = request.files.to_dict()
|
|
|
|
|
- mode = dict_video_["mode"]
|
|
|
|
|
|
|
+ dict_video_=request.form.to_dict()
|
|
|
|
|
+ dict_video_mp4=request.files.to_dict()
|
|
|
|
|
+
|
|
|
|
|
+ ff=dict_video_mp4["video"]
|
|
|
|
|
+ mode=dict_video_["mode"]
|
|
|
|
|
+
|
|
|
global global_video_index
|
|
global global_video_index
|
|
|
- global_video_index = int(add_new_data_dyna(mode))
|
|
|
|
|
- for file in dict_video_mp4():
|
|
|
|
|
- base = "./video/"
|
|
|
|
|
- filename = base + str(global_video_index) + ".mp4"
|
|
|
|
|
- file.save(filename)
|
|
|
|
|
- return {"id": str(global_video_index)}
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
-def save_videos(file):
|
|
|
|
|
- base = "video_pose/input/"
|
|
|
|
|
- filename = file.filename
|
|
|
|
|
- # global_index[0] = index
|
|
|
|
|
- save_name = base + filename
|
|
|
|
|
- print(filename)
|
|
|
|
|
- print(save_name)
|
|
|
|
|
- file.save(save_name)
|
|
|
|
|
|
|
+ global_video_index=int(add_new_data_dyna(mode))
|
|
|
|
|
|
|
|
|
|
+ base="./video/"
|
|
|
|
|
+ filename=base+str(global_video_index)+".mp4"
|
|
|
|
|
|
|
|
-##jump
|
|
|
|
|
-##result["jump_power"]["level"]/["path"]/["val"]
|
|
|
|
|
-##result["core_strength"]["level"]/["path"] 1 2 3 4
|
|
|
|
|
-##result["landing_position"]["level"]/["path"]["val"]
|
|
|
|
|
-##juanfu
|
|
|
|
|
-## result["head_power"]["level"]/["path"]/["val"]
|
|
|
|
|
-##result["core_strength"]["level"]/["path"]
|
|
|
|
|
-##result["body_stability"]["level"]/["val"]
|
|
|
|
|
|
|
+ ff.save(filename)
|
|
|
|
|
|
|
|
-##pingban
|
|
|
|
|
-"""
|
|
|
|
|
-result["arm_strength"]["level"]/["path"]/["val"]
|
|
|
|
|
-result["stability"]["level"]/["path"]/["val"]
|
|
|
|
|
-result["standard"]["level"]/["path"]/["val"]
|
|
|
|
|
-"""
|
|
|
|
|
-##shendun
|
|
|
|
|
-"""
|
|
|
|
|
-result["leg_strength"]["level"]/["path"]
|
|
|
|
|
-"""
|
|
|
|
|
-##gaotaitui
|
|
|
|
|
-"""
|
|
|
|
|
-result["standard"]["level"]/["path"]
|
|
|
|
|
-"""
|
|
|
|
|
|
|
+ return {"id":str(global_video_index)}
|
|
|
|
|
|
|
|
|
|
|
|
|
-@app.route('/get_video_data', methods=['POST'])
|
|
|
|
|
|
|
+@app.route('/get_video_data',methods=['POST'])
|
|
|
@cross_origin()
|
|
@cross_origin()
|
|
|
def get_video_data():
|
|
def get_video_data():
|
|
|
- dict_video_ = request.form.to_dict()
|
|
|
|
|
|
|
+ dict_video_=request.form.to_dict()
|
|
|
global global_video_index
|
|
global global_video_index
|
|
|
- global_video_index = int(dict_video_["id"])
|
|
|
|
|
- mode = str(lookup_data(global_video_index)) # get database mode
|
|
|
|
|
- re = run_video(mode, global_video_index, 1)
|
|
|
|
|
|
|
+ global_video_index=int(dict_video_["id"])
|
|
|
|
|
+ mode=str(lookup_data(global_video_index))#get database mode
|
|
|
|
|
+ re=run_video(mode,global_video_index,1)
|
|
|
return re
|
|
return re
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-@app.route('/get_3D', methods=['POST'])
|
|
|
|
|
|
|
+@app.route('/get_video_status',methods=['POST'])
|
|
|
@cross_origin()
|
|
@cross_origin()
|
|
|
-def get_3D():
|
|
|
|
|
- return
|
|
|
|
|
|
|
+def get_video_status():
|
|
|
|
|
+ dict_video_=request.form.to_dict()
|
|
|
|
|
+ global global_video_index
|
|
|
|
|
+ global_video_index=int(dict_video_["id"])
|
|
|
|
|
+ bool=get_status(global_video_index)==1
|
|
|
|
|
+ return {"state":get_status(global_video_index)==1}
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
-@app.route('/query_3D', methods=['POST'])
|
|
|
|
|
|
|
+@app.route('/query_video',methods=['POST'])
|
|
|
@cross_origin()
|
|
@cross_origin()
|
|
|
def query_video():
|
|
def query_video():
|
|
|
- dict_video_ = request.form.to_dict()
|
|
|
|
|
- global global_video_index
|
|
|
|
|
- global_video_index = int(dict_video_["id"])
|
|
|
|
|
- return lookup_video(global_video_index, 0)
|
|
|
|
|
-
|
|
|
|
|
|
|
+ dict_video_=request.form.to_dict()
|
|
|
|
|
+ print(dict_video_)
|
|
|
|
|
+ global global_video_index
|
|
|
|
|
+ global_video_index=int(dict_video_["id"])
|
|
|
|
|
+ print(global_video_index)
|
|
|
|
|
+ return lookup_video(global_video_index,0)
|
|
|
|
|
+
|
|
|
|
|
+@app.route('/get_3D',methods=['POST'])
|
|
|
|
|
+@cross_origin()
|
|
|
|
|
+def get_3D():
|
|
|
|
|
+ return "404"
|
|
|
|
|
|
|
|
-@app.route('/query_video', methods=['POST'])
|
|
|
|
|
|
|
+@app.route('/query_3D',methods=['POST'])
|
|
|
@cross_origin()
|
|
@cross_origin()
|
|
|
def query_3D():
|
|
def query_3D():
|
|
|
- return
|
|
|
|
|
|
|
+ return 404
|
|
|
|
|
|
|
|
|
|
+#result={xx:xx,xx:xx}
|
|
|
|
|
+#result={power:{val:xx,path:xx},strength:{val:xx,path:xx}}
|
|
|
|
|
|
|
|
-# result={xx:xx,xx:xx}
|
|
|
|
|
-# result={power:{val:xx,path:xx},strength:{val:xx,path:xx}}
|
|
|
|
|
-
|
|
|
|
|
-# 1.锻炼建议
|
|
|
|
|
-# 2.发送视频
|
|
|
|
|
-# 3.
|
|
|
|
|
|
|
+#1.锻炼建议
|
|
|
|
|
+#2.发送视频
|
|
|
|
|
+#3.
|
|
|
|
|
|
|
|
@app.route('/send_form', methods=['POST'])
|
|
@app.route('/send_form', methods=['POST'])
|
|
|
@cross_origin()
|
|
@cross_origin()
|
|
@@ -282,14 +282,14 @@ def send_form():
|
|
|
|
|
|
|
|
fileList = request.files.to_dict()
|
|
fileList = request.files.to_dict()
|
|
|
global global_index
|
|
global global_index
|
|
|
- global_index[0] = int(add_new_data())
|
|
|
|
|
- for file in fileList.values():
|
|
|
|
|
- save_images(file)
|
|
|
|
|
|
|
+ global_index[0]=int(add_new_data())
|
|
|
|
|
+ for filed in fileList.values():
|
|
|
|
|
+ save_file(filed)
|
|
|
height = float(text_data["height"]) if text_data["height"] != "undefined" else None
|
|
height = float(text_data["height"]) if text_data["height"] != "undefined" else None
|
|
|
run_the_process(global_index[0], height)
|
|
run_the_process(global_index[0], height)
|
|
|
process_db(int(global_index[0]))
|
|
process_db(int(global_index[0]))
|
|
|
return {
|
|
return {
|
|
|
- "id": global_index[0],
|
|
|
|
|
|
|
+ "id":global_index[0],
|
|
|
"status": True if height is not None else False
|
|
"status": True if height is not None else False
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -306,7 +306,7 @@ def run_project():
|
|
|
id = request.form.to_dict()["id"]
|
|
id = request.form.to_dict()["id"]
|
|
|
print(id)
|
|
print(id)
|
|
|
base = "pose_processed_images"
|
|
base = "pose_processed_images"
|
|
|
- global_index[0] = int(id)
|
|
|
|
|
|
|
+ global_index[0]=int(id)
|
|
|
read_pose_processes_txt_result()
|
|
read_pose_processes_txt_result()
|
|
|
print(base + "/" + str(global_index[0]) + "-0-result.png")
|
|
print(base + "/" + str(global_index[0]) + "-0-result.png")
|
|
|
return {
|
|
return {
|
|
@@ -316,10 +316,14 @@ def run_project():
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
if __name__ == '__main__':
|
|
if __name__ == '__main__':
|
|
|
# read_pose_processes_txt_result()
|
|
# read_pose_processes_txt_result()
|
|
|
# print(list_to_json(li_return))
|
|
# print(list_to_json(li_return))
|
|
|
|
|
|
|
|
- # app.run()
|
|
|
|
|
- app.run(host="0.0.0.0", port=8090, debug=True)
|
|
|
|
|
|
|
+ #app.run()
|
|
|
|
|
+ app.run(host="0.0.0.0", port=8090,debug=True)
|
|
|
|
|
+ #app.run(host="0.0.0.0", port=8090)
|
|
|
CORS(app, resouces=r'/*')
|
|
CORS(app, resouces=r'/*')
|
|
|
|
|
+ #run_video("gaotaitui",27,0)
|
|
|
|
|
+ lookup_video(41,0)
|