| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350 |
- import base64
- from video_to_photo import run
- import os
- import advice
- def get_base64(path):
- with open(path, "rb") as f:
- base64_data = base64.b64encode(f.read())
- return base64_data.decode()
- def classify_jump(name, re):
- q = "./capture_image/" + name
- qqq = os.path.abspath(q)
- result = {}
- result["jump_power"] = {}
- if (float(re["1"]["val"]) > 140.0):
- result["jump_power"]["level"] = 1
- elif (float(re["1"]["val"]) > 115.0):
- result["jump_power"]["level"] = 2
- elif (float(re["1"]["val"]) > 90.0):
- result["jump_power"]["level"] = 3
- else:
- result["jump_power"]["level"] = 4
- r = "capture_image_result" + str(re["1"]["num"]) + ".png"
- a = os.path.join(qqq, r)
- # result["jump_power"]["path"]=get_base64(a)
- result["jump_power"]["val"] = re["1"]["val"]
- result["core_strength"] = {}
- if (float(re["2"]["val"]) < 8.0):
- result["core_strength"]["level"] = 1
- elif (float(re["2"]["val"]) < 15.0):
- result["core_strength"]["level"] = 2
- elif (float(re["2"]["val"]) < 30.0):
- result["core_strength"]["level"] = 3
- else:
- result["core_strength"]["level"] = 4
- r = "capture_image_result" + str(re["2"]["num"]) + ".png"
- a = os.path.join(qqq, r)
- # result["core_strength"]["path"]=get_base64(a)
- result["landing_position"] = {}
- if (float(re["3"]["val"]) > 140.0):
- result["landing_position"]["level"] = 1
- elif (float(re["3"]["val"]) > 115.0):
- result["landing_position"]["level"] = 2
- elif (float(re["3"]["val"]) > 90.0):
- result["landing_position"]["level"] = 3
- else:
- result["landing_position"]["level"] = 4
- r = "capture_image_result" + str(re["3"]["num"]) + ".png"
- a = os.path.join(qqq, r)
- # result["landing_position"]["path"]=get_base64(a)
- result["landing_position"]["val"] = re["3"]["val"]
- result["advice"] = advice.ad_jump(result)
- res = []
- d = {}
- d["item"] = "jump_power"
- d["a"] = str(5 - int(result["jump_power"]["level"]))
- d["val"] = result["jump_power"]["val"]
- # d["path"]=result["arm_strength"]["path"]
- res.append(d)
- d = {}
- d["item"] = "core_strength"
- d["a"] = 5 - int(result["core_strength"]["level"])
- # d["path"]=result["stability"]["path"]
- res.append(d)
- d = {}
- d["item"] = "landing_position"
- d["a"] = 5 - int(result["landing_position"]["level"])
- d["val"] = result["landing_position"]["val"]
- # d["path"]=result["standard"]["path"]
- res.append(d)
- # d={}
- # d["item"]="advice"
- # d["a"]=result["advice"]
- # res.append(d)
- return {"analyzed_data": res, "advice": result["advice"]}
- def classify_juanfu(name, re):
- q = "./capture_image/" + name
- qqq = os.path.abspath(q)
- result = {}
- result["head_power"] = {}
- if (float(re["1"]["val"]) > 100.0):
- result["head_power"]["level"] = 1
- elif (float(re["1"]["val"]) > 90.0):
- result["head_power"]["level"] = 2
- elif (float(re["1"]["val"]) > 80.0):
- result["head_power"]["level"] = 3
- else:
- result["head_power"]["level"] = 4
- r = "capture_image_result" + str(re["1"]["num"]) + ".png"
- a = os.path.join(qqq, r)
- # result["head_power"]["path"]=get_base64(a)
- result["head_power"]["val"] = re["1"]["val"]
- result["core_strength"] = {}
- if (float(re["2"]["val"]) > 90):
- result["core_strength"]["level"] = 1
- elif (float(re["2"]["val"]) > 80):
- result["core_strength"]["level"] = 2
- elif (float(re["2"]["val"]) > 70):
- result["core_strength"]["level"] = 3
- else:
- result["core_strength"]["level"] = 4
- r = "capture_image_result" + str(re["2"]["num"]) + ".png"
- a = os.path.join(qqq, r)
- result["core_strength"]["path"] = get_base64(a)
- result["body_stability"] = {}
- if (float(re["4"]["num"]) < 15):
- result["body_stability"]["level"] = 1
- elif (float(re["4"]["num"]) < 20):
- result["body_stability"]["level"] = 2
- elif (float(re["4"]["num"]) < 30):
- result["body_stability"]["level"] = 3
- else:
- result["body_stability"]["level"] = 4
- result["body_stability"]["val"] = re["4"]["num"]
- result["advice"] = advice.ad_juanfu(result)
- res = []
- d = {}
- d["item"] = "head_power"
- d["a"] = 5 - int(result["head_power"]["level"])
- d["val"] = result["head_power"]["val"]
- # d["path"]=result["arm_strength"]["path"]
- res.append(d)
- d = {}
- d["item"] = "core_strength"
- d["a"] = 5 - int(result["core_strength"]["level"])
- # d["path"]=result["stability"]["path"]
- res.append(d)
- d = {}
- d["item"] = "body_stability"
- d["a"] = 5 - int(result["body_stability"]["level"])
- d["val"] = result["body_stability"]["val"]
- # d["path"]=result["standard"]["path"]
- res.append(d)
- # d={}
- # d["item"]="advice"
- # d["a"]=result["advice"]
- # res.append(d)
- return {"analyzed_data": res, "advice": result["advice"]}
- def classify_pingban(name, re):
- q = "./capture_image/" + name
- qqq = os.path.abspath(q)
- result = {}
- result["arm_strength"] = {}
- dis = abs(90 - float(re["1"]["val"]))
- if (dis < 5):
- result["arm_strength"]["level"] = 1
- elif (dis < 10):
- result["arm_strength"]["level"] = 2
- elif (dis < 20):
- result["arm_strength"]["level"] = 3
- else:
- result["arm_strength"]["level"] = 4
- r = "capture_image_result" + str(re["1"]["num"]) + ".png"
- a = os.path.join(qqq, r)
- # result["arm_strength"]["path"]=get_base64(a)
- result["arm_strength"]["val"] = re["1"]["val"]
- result["stability"] = {}
- if (float(re["2"]["val"]) < 5):
- result["stability"]["level"] = 1
- elif (float(re["2"]["val"]) < 10):
- result["stability"]["level"] = 2
- elif (float(re["2"]["val"]) < 15):
- result["stability"]["level"] = 3
- else:
- result["stability"]["level"] = 4
- r = "capture_image_result" + str(re["2"]["num"]) + ".png"
- a = os.path.join(qqq, r)
- # result["stability"]["path"]=get_base64(a)
- result["stability"]["val"] = re["2"]["val"]
- result["standard"] = {}
- if (float(re["3"]["val"]) < 5):
- result["standard"]["level"] = 1
- elif (float(re["3"]["val"]) < 10):
- result["standard"]["level"] = 2
- elif (float(re["3"]["val"]) < 15):
- result["standard"]["level"] = 3
- else:
- result["standard"]["level"] = 4
- r = "capture_image_result" + str(re["3"]["num"]) + ".png"
- a = os.path.join(qqq, r)
- result["standard"]["path"] = get_base64(a)
- result["standard"]["val"] = re["3"]["val"]
- result["advice"] = advice.ad_pingban(result)
- res = []
- d = {}
- d["item"] = "arm_arm_strength"
- d["a"] = 5 - int(result["arm_strength"]["level"])
- d["val"] = result["arm_strength"]["val"]
- # d["path"]=result["arm_strength"]["path"]
- res.append(d)
- d = {}
- d["item"] = "stability"
- d["a"] = 5 - int(result["stability"]["level"])
- d["val"] = result["stability"]["val"]
- # d["path"]=result["stability"]["path"]
- res.append(d)
- d = {}
- d["item"] = "standard"
- d["a"] = 5 - int(result["standard"]["level"])
- d["val"] = result["standard"]["val"]
- # d["path"]=result["standard"]["path"]
- res.append(d)
- # d={}
- # d["item"]="advice"
- # d["a"]=result["advice"]
- # res.append(d)
- return {"analyzed_data": res, "advice": result["advice"]}
- def classify_shendun(name, re):
- q = "./capture_image/" + name
- qqq = os.path.abspath(q)
- result = {}
- result["leg_strength"] = {}
- if (float(re["1"]["val"]) < 60):
- result["leg_strength"]["level"] = 1
- elif (float(re["1"]["val"]) < 80):
- result["leg_strength"]["level"] = 2
- elif (float(re["1"]["val"]) < 90):
- result["leg_strength"]["level"] = 3
- else:
- result["leg_strength"]["level"] = 4
- r = "capture_image_result" + str(re["1"]["num"]) + ".png"
- a = os.path.join(qqq, r)
- # result["leg_strength"]["path"]=get_base64(a)
- result["advice"] = advice.ad_shendun(result)
- # return result
- res = []
- d = {}
- d["item"] = "leg_strengthh"
- d["a"] = 5 - int(result["leg_strength"]["level"])
- # d["val"]=result["arm_strength"]["val"]
- # d["path"]=result["arm_strength"]["path"]
- res.append(d)
- # d={}
- # d["item"]="advice"
- # d["a"]=result["advice"]
- # res.append(d)
- return {"analyzed_data": res, "advice": result["advice"]}
- def classify_gaotaitui(name, re):
- q = "./capture_image/" + name
- qqq = os.path.abspath(q)
- result = {}
- result["standard"] = {}
- if (float(re["1"]["val"]) < 40):
- result["standard"]["level"] = 1
- elif (float(re["1"]["val"]) < 70):
- result["standard"]["level"] = 2
- elif (float(re["1"]["val"]) < 100):
- result["standard"]["level"] = 3
- else:
- result["standard"]["level"] = 4
- r = "capture_image_result" + str(re["1"]["num"]) + ".png"
- a = os.path.join(qqq, r)
- # result["standard"]["path"]=get_base64(a)
- result["advice"] = advice.ad_gaotaitui(result)
- # return result
- #
- res = []
- d = {}
- d["item"] = "standard"
- d["a"] = 5 - int(result["standard"]["level"])
- # d["val"]=result["standard"]["val"]
- # d["path"]=result["arm_strength"]["path"]
- res.append(d)
- # d={}
- # d["item"]="advice"
- # d["a"]=result["advice"]
- # res.append(d)
- return {"analyzed_data": res, "advice": result["advice"]}
- def classify_result(video_path, re, mode):
- # video_path = "./video/demo1.mp4"
- path = video_path
- os.path.split(path)
- tur = os.path.split(path)
- name = tur[len(tur) - 1].split('.')[0]
- switch = {'jump': classify_jump,
- 'pingban': classify_pingban,
- 'juanfu': classify_juanfu,
- 'shendun': classify_shendun,
- 'gaotaitui': classify_gaotaitui,
- }
- choice = mode
- power = switch.get(choice)(name, re)
- print(power)
- return power
- def api_dyna(path, mode, ana):
- return classify_result(path, run(path, mode, ana), mode)
- if __name__ == '__main__':
- # path="./video/demo1.mp4"
- # api_dyna(path,"jump",0)
- # classify_result(path,run(path,"jump",0),"jump")
- # path="./video/juanfu.mp4"
- # api_dyna(path,"juanfu",0)
- # classify_result(path,run(path,"juanfu",0),"juanfu")
- # path = "./video/jump.mp4"
- # api_dyna(path, "jump", 0)
- # run(path, "jump", 0)
- # classify_result(path,run(path,"pingban",0),"pingban")
- # path="./video/gaotaitui.mp4"
- # api_dyna(path,"gaotaitui",0)
- # classify_result(path,run(path,"gaotaitui",0),"gaotaitui")
- # path="./video/shendun.mp4"
- # api_dyna(path,"shendun",0)
- '''
- os.path.split(path)
- tur=os.path.split(path)
- name=tur[len(tur)-1].split('.')[0]
- p=os.getcwd()
- q="./capture_image"+name
- qqq=os.path.abspath(q)
- #print(qqq)
- r="capture_image_result"+"48"+".png"
- a=os.path.join(qqq,r)
- '''
|