|
|
@@ -7,6 +7,8 @@ from PIL import Image
|
|
|
import base64
|
|
|
|
|
|
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
|
|
|
@@ -17,107 +19,6 @@ bJson = ""
|
|
|
global_index = [6]
|
|
|
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
|
|
|
@@ -149,30 +50,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
|
|
|
@@ -219,8 +120,6 @@ def run_the_process(index: int = 0, height: float = 110):
|
|
|
# import analyse_func
|
|
|
#print(global_index[0])
|
|
|
do_analysis(global_index[0], height)
|
|
|
-
|
|
|
-
|
|
|
# 把list转化为可以直接返回的json格式
|
|
|
|
|
|
def list_to_json(li):
|
|
|
@@ -228,7 +127,6 @@ def list_to_json(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/" + \
|
|
|
@@ -236,11 +134,7 @@ def list_to_json(li):
|
|
|
# print(dict1)
|
|
|
return aJson
|
|
|
# print(dic_data)
|
|
|
-
|
|
|
-
|
|
|
app = Flask(__name__)
|
|
|
-
|
|
|
-
|
|
|
def save_file(file):
|
|
|
base = "pose_source_images/"
|
|
|
filename = file.filename
|
|
|
@@ -267,6 +161,24 @@ def save_file(file):
|
|
|
file.save(save_name)
|
|
|
print(filename)
|
|
|
print(save_name)
|
|
|
+#运行动态分析的入口
|
|
|
+def run_video(mode,ana=1):
|
|
|
+ num=add_new_data_dyna(mode)
|
|
|
+ q="./video/"+str(num)+".mp4"
|
|
|
+ #qqq=os.path.abspath(q)
|
|
|
+ #r="capture_image"+str(re["2"]["num"])+".png"
|
|
|
+ #a=os.path.join(qqq,r)
|
|
|
+ video_path=q
|
|
|
+ re= api_dyna(q,mode,ana)
|
|
|
+ return re
|
|
|
+
|
|
|
+def lookup_video(num,ana=0):
|
|
|
+
|
|
|
+ q="./video/"+str(num)+".mp4"
|
|
|
+ video_path=q
|
|
|
+ mode=lookup_data(num)
|
|
|
+ re= api_dyna(q,mode,ana)
|
|
|
+ return re
|
|
|
|
|
|
|
|
|
@app.route('/send_form', methods=['POST'])
|
|
|
@@ -282,7 +194,7 @@ def send_form():
|
|
|
run_the_process(global_index[0], height)
|
|
|
process_db(int(global_index[0]))
|
|
|
return {
|
|
|
- "id":global_index[0],
|
|
|
+ "id":global_index[0],
|
|
|
"status": True if height is not None else False
|
|
|
}
|
|
|
|
|
|
@@ -317,3 +229,5 @@ if __name__ == '__main__':
|
|
|
#app.run()
|
|
|
app.run(host="0.0.0.0", port=8090,debug=True)
|
|
|
CORS(app, resouces=r'/*')
|
|
|
+
|
|
|
+
|