CHWHC 4 лет назад
Родитель
Сommit
1420f70290
3 измененных файлов с 110 добавлено и 20 удалено
  1. 80 0
      backend/advice.py
  2. 20 15
      backend/classify.py
  3. 10 5
      backend/video_to_photo.py

+ 80 - 0
backend/advice.py

@@ -0,0 +1,80 @@
+def ad_jump(result):
+    ret=""
+    if(result["jump_power"]["level"]==3):
+        ret=ret+"Need to do more to promote leg muscle strength. "
+    elif(result["jump_power"]["level"]==4):
+        ret="The leg muscle is weak and the position needs to be improved. "
+
+    if(result["core_strength"]["level"]==3):
+        ret=ret+"The core strength need to be improved. "
+    elif result["core_strength"]["level"]==4:
+        ret=ret+"More practice to do to promote the core strength. "
+
+    if(result["landing_position"]["level"]==3):
+        ret=ret+"The landing position is not standard enough. Take some practice on the leg. "
+    elif result["landing_position"]["level"]==4:
+        ret=ret+"The landing position is far from standard, see some relavant video to correct posture. "
+    if(ret==""):
+        ret="The jump is good and keep it!"
+    return ret
+
+def ad_juanfu(result):
+    ret=""
+    if(result["head_power"]["level"]==3):
+        ret=ret+"Need to do more to promote head muscle strength. "
+    elif(result["head_power"]["level"]==4):
+        ret="The neck and abdominal muscles are weak and the position needs to be improved. "
+
+    if(result["core_strength"]["level"]==3):
+        ret=ret+"The core strength need to be improved.See some relavent video to promote it. "
+    elif result["core_strength"]["level"]==4:
+        ret=ret+"More practice to do to promote the core strength. "
+
+    if(result["body_stability"]["level"]==3):
+        ret=ret+"The body_stability is not enough. Take some practice on the leg. "
+    elif result["body_stability"]["level"]==4:
+        ret=ret+"The body_stability is far from standard, see some relavant video to correct posture . "
+    if(ret==""):
+        ret="The abdominal campaign is good and keep it!"
+    return ret
+
+def ad_pingban(result):
+    ret=""
+    if(result["arm_strength"]["level"]==3):
+        ret=ret+"Need to do more to promote arm muscle strength. "
+    elif(result["arm_strength"]["level"]==4):
+        ret="The forearm strength are inadequate and the position needs to be improved. "
+
+    if(result["stability"]["level"]==3):
+        ret=ret+"The core strength need to be improved.Try to lengthen duration time and frequency. "
+    elif result["stability"]["level"]==4:
+        ret=ret+"More practice to do to promote the stability . "
+
+    if(result["standard"]["level"]==3):
+        ret=ret+"Plank movements are less than standard and require more straight leg support. "
+    elif result["standard"]["level"]==4:
+        ret=ret+"The body posture is far from standard ,see the standard video and improve leg strength. "
+    if(ret==""):
+        ret="Plank moves are fine, and your goal is to maximize your endurance!"
+    return ret
+
+def ad_shendun(result):
+    if(result["leg_strength"]["level"]==1):
+        return "The posture is good and remember to enhance endurance. "
+    elif result["leg_strength"]["level"]==2:
+        return "Try a wider squat."
+
+    elif result["leg_strength"]["level"]==3:
+        return "Squat range is far from enough, more practice thigh strength. "
+    else:
+        return "Check out some video to learn about standard postures and work on your thigh and calf muscles"
+
+def ad_gaotaitui(result):
+    if(result["standard"]["level"]==1):
+        return "The posture is good and remember to enhance endurance. "
+    elif result["standard"]["level"]==2:
+        return "Try to elevate your thighs to increase intensity. "
+    elif result["standard"]["level"]==3:
+        return "High leg lift is not enough, more practice thigh strength. "
+    else:
+        return "Check out some video to learn about standard postures and work on your thigh and calf muscles"

+ 20 - 15
backend/classify.py

@@ -1,5 +1,6 @@
 from video_to_photo import run
 import os
+import advice
 
 def classify_jump(name,re):
     q="./capture_image/"+name
@@ -48,7 +49,7 @@ def classify_jump(name,re):
     a=os.path.join(qqq,r)
     result["landing_position"]["path"]=a
     result["landing_position"]["val"]=re["3"]["val"]
-
+    result["advice"]= advice.ad_jump(result)
 
     return result
 def classify_juanfu(name,re):
@@ -73,11 +74,11 @@ def classify_juanfu(name,re):
     result["head_power"]["val"]=re["1"]["val"]
 
     result["core_strength"]={}
-    if(float(re["2"]["val"])>75):
+    if(float(re["2"]["val"])>90):
         result["core_strength"]["level"]=1
-    elif (float(re["2"]["val"])>70):
+    elif (float(re["2"]["val"])>80):
         result["core_strength"]["level"]=2
-    elif (float(re["2"]["val"])>60):
+    elif (float(re["2"]["val"])>70):
         result["core_strength"]["level"]=3
     else:
         result["core_strength"]["level"]=4
@@ -88,15 +89,16 @@ def classify_juanfu(name,re):
     result["body_stability"]={}
     if(float(re["4"]["num"])<15):
         result["body_stability"]["level"]=1
-    elif (float(re["4"]["val"])<20):
+    elif (float(re["4"]["num"])<20):
         result["body_stability"]["level"]=2
-    elif (float(re["4"]["val"])<30):
+    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)
     return result
 
 def classify_pingban(name,re):
@@ -148,7 +150,7 @@ def classify_pingban(name,re):
     a=os.path.join(qqq,r)
     result["standard"]["path"]=a
     result["standard"]["val"]=re["3"]["val"]
-
+    result["advice"]=advice.ad_pingban(result)
 
     return result
 def classify_shendun(name,re):
@@ -168,6 +170,7 @@ def classify_shendun(name,re):
     r="capture_image"+str(re["1"]["num"])+".png"
     a=os.path.join(qqq,r)
     result["leg_strength"]["path"]=a
+    result["advice"]=advice.ad_shendun(result)
     return result
 def classify_gaotaitui(name,re):
     q="./capture_image/"+name
@@ -186,6 +189,7 @@ def classify_gaotaitui(name,re):
     r="capture_image"+str(re["1"]["num"])+".png"
     a=os.path.join(qqq,r)
     result["standard"]["path"]=a
+    result["advice"]=advice.ad_gaotaitui(result)
     return result
 
 
@@ -204,27 +208,28 @@ def classify_result(video_path,re,mode):
               'gaotaitui':classify_gaotaitui,
               }
     choice=mode
-    power=switch.get(choice,classify_jump)(video_path,re)
+    power=switch.get(choice,classify_jump)(name,re)
+    print(power)
     return power
 
-def api_dyna(video_path,mode,ana=1):
+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)
+    #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)
+    #path="./video/juanfu.mp4"
+    #api_dyna(path,"juanfu",0)
     #classify_result(path,run(path,"juanfu",0),"juanfu")
     path="./video/pingban.mp4"
     api_dyna(path,"pingban",0)
-    #classify_result(path,run(path,"pingban",0),"pingban")
+    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")
+    classify_result(path,run(path,"gaotaitui",0),"gaotaitui")
     path="./video/shendun.mp4"
     api_dyna(path,"shendun",0)
     '''

+ 10 - 5
backend/video_to_photo.py

@@ -11,6 +11,7 @@ import os
 
 
 
+
 def split_video(path):
     video_path = path
     os.path.split(path)
@@ -283,6 +284,7 @@ def ignore_data_juanfu(result):
 
 
 def ignore_data_gaotaitui(result):
+
     result_ig=result
     k="0"
     last={}
@@ -304,8 +306,9 @@ def ignore_data_gaotaitui(result):
             if(float(result_ig[i]["knee_ankle_r_angle"])>120 and float(result_ig[i]["hip_knee_r_angle"])<90):
                 panduan[i]=result_ig[i]["r_d"]
     f=0
-    ma=0
-    key_k=0
+    #ma=0
+    ma=panduan[k]
+    key_k=k
     for key in panduan:
         if f==0:
             ma=panduan[key]
@@ -439,10 +442,12 @@ def write1(result,name):
     return name
 
 
-def run(video_path,mode,need_split=1):
+def run(video_path,mode,need_split):
     path=video_path
     os.path.split(path)
     tur=os.path.split(path)
+    if(mode=="pingban"):
+        print(need_split)
     name=tur[len(tur)-1].split('.')[0]
     if(need_split==1):
         c=split_video(video_path)
@@ -450,7 +455,7 @@ def run(video_path,mode,need_split=1):
         gather_video(video_path)
     do_analysis("./capture_image/"+name+"/capture_image{}-1.png.npy",video_path,mode)
 
-    switch = {'longjump': ignore_data_jump,                # 注意此处不要加括号
+    switch = {'jump': ignore_data_jump,                # 注意此处不要加括号
               'pingban': ignore_data_pingban,
               'juanfu': ignore_data_juanfu,
               'shendun':ignore_data_shendun,
@@ -484,7 +489,7 @@ if __name__ == '__main__':
     #print(re)
     re=run(video_path,"shendun",0)
     #参数一 video_path
-    #参数二 shendun jump gaotaitui juanfu pingbanzhicheng
+    #参数二 shendun jump gaotaitui juanfu pingban
     #第三个参数为1 表示需要视频切割