|
|
@@ -6,7 +6,9 @@ from flask_cors import *
|
|
|
from PIL import Image
|
|
|
import base64
|
|
|
|
|
|
-from analyse_func import do_analysis
|
|
|
+from analyse_func import do_analysis
|
|
|
+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
|
|
|
|
|
|
# str_res=""
|
|
|
# a dict contains the txt
|
|
|
@@ -15,114 +17,9 @@ li_last = []
|
|
|
# store dic_data's json format
|
|
|
bJson = ""
|
|
|
global_index = [6]
|
|
|
+global_video_index=0
|
|
|
li_return = []
|
|
|
img_return = []
|
|
|
-ip_ad = "106.15.1.178"
|
|
|
-
|
|
|
-import pymysql
|
|
|
-
|
|
|
-db = pymysql.connect(host=ip_ad,
|
|
|
- user="root",
|
|
|
- password="root",
|
|
|
- port=3306, # 端口
|
|
|
- charset='utf8')
|
|
|
-
|
|
|
-cursor = db.cursor()
|
|
|
-
|
|
|
-
|
|
|
-def create_db():
|
|
|
- db = pymysql.connect(host=ip_ad,
|
|
|
- user="root",
|
|
|
- password="root",
|
|
|
- # port=3306, # 端口
|
|
|
- # charset='utf8')
|
|
|
- )
|
|
|
-
|
|
|
- cursor = db.cursor()
|
|
|
- # 使用 execute() 方法执行 SQL,如果表存在则删除
|
|
|
- # cursor.execute("DROP TABLE IF EXISTS pose")
|
|
|
-
|
|
|
- # 使用预处理语句创建表
|
|
|
- cursor.execute("create database if not exists pose")
|
|
|
- db.commit()
|
|
|
- db.close()
|
|
|
- cursor.close()
|
|
|
-
|
|
|
-
|
|
|
-def create_table():
|
|
|
- db = pymysql.connect(host=ip_ad,
|
|
|
- user="root",
|
|
|
- password="root",
|
|
|
- port=3306, # 端口
|
|
|
- charset='utf8',
|
|
|
- database="pose")
|
|
|
-
|
|
|
- cursor = db.cursor()
|
|
|
-
|
|
|
- sql = """CREATE TABLE pose(
|
|
|
- id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
|
|
- status INT)
|
|
|
- """
|
|
|
- insert_table_sql = """INSERT INTO `pose` (`status`) VALUES ('0')"""
|
|
|
-
|
|
|
- cursor.execute(sql)
|
|
|
- db.commit()
|
|
|
- cursor.execute(insert_table_sql)
|
|
|
- version = cursor.fetchone()
|
|
|
- print(version)
|
|
|
- db.commit()
|
|
|
- db.close()
|
|
|
-
|
|
|
-
|
|
|
-def add_new_data():
|
|
|
- db = pymysql.connect(host=ip_ad,
|
|
|
- user="root",
|
|
|
- password="root",
|
|
|
- port=3306, # 端口
|
|
|
- database="pose",
|
|
|
- charset='utf8')
|
|
|
-
|
|
|
- cursor = db.cursor()
|
|
|
-
|
|
|
- insert_table_sql = """INSERT INTO `pose` (`status`) VALUES ( '0')"""
|
|
|
- cursor.execute(insert_table_sql)
|
|
|
- db.commit()
|
|
|
- db.close()
|
|
|
- cursor.close()
|
|
|
- return_id = cursor.lastrowid
|
|
|
- return return_id
|
|
|
-
|
|
|
-
|
|
|
-def process_db(id):
|
|
|
- db = pymysql.connect(host=ip_ad,
|
|
|
- user="root",
|
|
|
- password="root",
|
|
|
- port=3306, # 端口
|
|
|
- database="pose",
|
|
|
- charset='utf8')
|
|
|
- sql = "update pose set status = 1 where id = %d " % id
|
|
|
- cursor = db.cursor()
|
|
|
- cursor.execute(sql)
|
|
|
- db.commit()
|
|
|
- cursor.close()
|
|
|
- db.close()
|
|
|
-
|
|
|
-
|
|
|
-def get_status(id):
|
|
|
- db = pymysql.connect(host=ip_ad,
|
|
|
- user="root",
|
|
|
- password="root",
|
|
|
- port=3306, # 端口
|
|
|
- database="pose",
|
|
|
- charset='utf8')
|
|
|
- sql = "select status from pose where id =%d" % id
|
|
|
- cursor = db.cursor()
|
|
|
- status = cursor.execute(sql)
|
|
|
- cursor.close()
|
|
|
- db.close()
|
|
|
- if str(status) == "1":
|
|
|
- return True
|
|
|
- return False
|
|
|
|
|
|
|
|
|
# read txt file and change it to the list format
|
|
|
@@ -154,30 +51,30 @@ def read_pose_processes_txt_result():
|
|
|
i = i + 1 # i是头部分析那行
|
|
|
dic_1["name"] = "头部分析"
|
|
|
dic_1["value"] = lines[i][5:len(lines[i]) - 1]
|
|
|
- i = i + 1
|
|
|
+ i = i + 1 # 头部数字级别
|
|
|
dic_1["level"] = int(lines[i].strip())
|
|
|
li.append(dic_1)
|
|
|
dic_2 = {}
|
|
|
- i += 2
|
|
|
+ i += 2 #第六行 i=6
|
|
|
dic_2["name"] = "肩部分析"
|
|
|
- num_risk_1 = int(lines[i + 1].strip())
|
|
|
- dic_2["value"] = lines[i][:-1] + " " + lines[(i + 2)][:-1]
|
|
|
- num_risk_2 = int(lines[i + 3].strip())
|
|
|
- dic_2["level"] = int(max(num_risk_1, num_risk_2))
|
|
|
+ #num_risk_1 = int(lines[i + 1].strip())
|
|
|
+ dic_2["value"] = lines[i][:-1] + " " + lines[(i + 1)][:-1]
|
|
|
+ num_risk_2 = int(lines[i + 2].strip())
|
|
|
+ dic_2["level"] = int(num_risk_2)
|
|
|
li.append(dic_2)
|
|
|
- i += 5
|
|
|
+ i += 4 #i=10
|
|
|
dic_3 = {}
|
|
|
dic_3["name"] = "髋部分析"
|
|
|
- dic_3["value"] = lines[i][:-1] + " " + lines[(i + 2)][:-1]
|
|
|
- num_risk_1 = int(lines[i + 1].strip())
|
|
|
- num_risk_2 = int(lines[i + 3].strip())
|
|
|
- dic_3["level"] = int(max(num_risk_1, num_risk_2))
|
|
|
- i += 5
|
|
|
- dic_4 = {"name": "腿型分析", "value": lines[i][:-1] + " " + lines[(i + 1)][:-1] + " " + lines[(i + 2)][:-1]}
|
|
|
+ dic_3["value"] = lines[i][:-1] + " " + lines[(i + 1)][:-1]
|
|
|
+ num_risk_1 = int(lines[i + 2].strip())
|
|
|
+ #num_risk_2 = int(lines[i + 3].strip())
|
|
|
+ dic_3["level"] = int(max(num_risk_1, 0))
|
|
|
+ i += 4 #i=14
|
|
|
+ dic_4 = {"name": "腿型分析", "value": lines[i][:-1]}
|
|
|
li.append(dic_3)
|
|
|
li.append(dic_4)
|
|
|
dic_data["detail"] = li
|
|
|
- if ("非" in lines[(i + 2)][:-1]):
|
|
|
+ if ("非" in lines[i][:-1]):
|
|
|
dic_4["level"] = 0
|
|
|
else:
|
|
|
dic_4["level"] = 1
|
|
|
@@ -222,18 +119,15 @@ def read_pose_processes_txt_result():
|
|
|
def run_the_process(index: int = 0, height: float = 110):
|
|
|
# sys.path.append("../analyse_func.py")
|
|
|
# import analyse_func
|
|
|
- # print(global_index[0])
|
|
|
+ #print(global_index[0])
|
|
|
do_analysis(global_index[0], height)
|
|
|
-
|
|
|
-
|
|
|
# 把list转化为可以直接返回的json格式
|
|
|
|
|
|
def list_to_json(li):
|
|
|
- # print(li)
|
|
|
+ #print(li)
|
|
|
|
|
|
aJson = json.dumps(li, ensure_ascii=False)
|
|
|
print(aJson)
|
|
|
-
|
|
|
# dict1={}
|
|
|
# dict1["front"]="/home/seecoder/Documents/pose-correction/pc-demo/pose_processed_images/"+str(global_index[0])+"-0-result.jpg"
|
|
|
# dict1["right"] = "/home/seecoder/Documents/pose-correction/pc-demo/pose_processed_images/" + \
|
|
|
@@ -241,8 +135,6 @@ def list_to_json(li):
|
|
|
# print(dict1)
|
|
|
return aJson
|
|
|
# print(dic_data)
|
|
|
-
|
|
|
-
|
|
|
app = Flask(__name__)
|
|
|
|
|
|
|
|
|
@@ -250,7 +142,7 @@ def save_images(file):
|
|
|
base = "pose_source_images/"
|
|
|
filename = file.filename
|
|
|
index = global_index[0]
|
|
|
- # global_index[0] = index
|
|
|
+ #global_index[0] = index
|
|
|
suffix = ".png"
|
|
|
if filename.find("jpg") > 0:
|
|
|
suffix = ".jpg"
|
|
|
@@ -272,6 +164,33 @@ def save_images(file):
|
|
|
file.save(save_name)
|
|
|
print(filename)
|
|
|
print(save_name)
|
|
|
+#运行动态分析的入口
|
|
|
+def run_video(mode,num,ana=1):
|
|
|
+ q="./video/"+str(num)+".mp4"
|
|
|
+ re= api_dyna(q,mode,ana)
|
|
|
+ return re
|
|
|
+
|
|
|
+def lookup_video(num,ana=0):
|
|
|
+ q="./video/"+str(num)+".mp4"
|
|
|
+ mode=lookup_data(num)
|
|
|
+ re= api_dyna(q,mode,ana)
|
|
|
+ return re
|
|
|
+
|
|
|
+###send a video and return a id marked the video (identical)
|
|
|
+@app.route('/get videoid',methods=['POST'])
|
|
|
+@cross_origin()
|
|
|
+def get_videoid():
|
|
|
+ dict_video_=request.form.to_dict()
|
|
|
+ dict_video_mp4=request.files.to_dict()
|
|
|
+ mode=dict_video_["mode"]
|
|
|
+ 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 = "3d_pose/input/"
|
|
|
@@ -284,10 +203,72 @@ def save_videos(file):
|
|
|
|
|
|
|
|
|
|
|
|
+##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"]
|
|
|
+"""
|
|
|
+
|
|
|
+@app.route('/get_video_data',methods=['POST'])
|
|
|
+@cross_origin()
|
|
|
+def get_video_data():
|
|
|
+ dict_video_=request.form.to_dict()
|
|
|
+ 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)
|
|
|
+ return re
|
|
|
+
|
|
|
+
|
|
|
+@app.route('/get_3D',methods=['POST'])
|
|
|
+@cross_origin()
|
|
|
+def get_3D():
|
|
|
+ return
|
|
|
+
|
|
|
+@app.route('/query_3D',methods=['POST'])
|
|
|
+@cross_origin()
|
|
|
+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)
|
|
|
+
|
|
|
+@app.route('/query_video',methods=['POST'])
|
|
|
+@cross_origin()
|
|
|
+def query_3D():
|
|
|
+ return
|
|
|
+
|
|
|
+
|
|
|
+#result={xx:xx,xx:xx}
|
|
|
+#result={power:{val:xx,path:xx},strength:{val:xx,path:xx}}
|
|
|
+
|
|
|
+#1.锻炼建议
|
|
|
+#2.发送视频
|
|
|
+#3.
|
|
|
+
|
|
|
@app.route('/send_form', methods=['POST'])
|
|
|
@cross_origin()
|
|
|
def send_form():
|
|
|
text_data = request.form.to_dict()
|
|
|
+
|
|
|
fileList = request.files.to_dict()
|
|
|
global global_index
|
|
|
global_index[0] = int(add_new_data())
|
|
|
@@ -302,16 +283,6 @@ def send_form():
|
|
|
}
|
|
|
|
|
|
|
|
|
-@app.route('/submit_video', methods=['POST'])
|
|
|
-@cross_origin()
|
|
|
-def send_video():
|
|
|
- # text_data = request.form.to_dict()
|
|
|
- fileList = request.files.to_dict()
|
|
|
- for file in fileList.values():
|
|
|
- save_videos(file)
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
def get_base64(path):
|
|
|
with open(path, "rb") as f:
|
|
|
base64_data = base64.b64encode(f.read())
|