张许妍 4 лет назад
Родитель
Сommit
9d1b8e6765

+ 9 - 9
backend_refactor/service/ai/video/inner_analyze.py

@@ -54,11 +54,11 @@ def cal_angle(point_a, point_b, point_c):
 
 def analyse_npy_side_juanfu(data):
     result = {}
-    data = data[0]
 
-    # if len(data) != 25:
-    #     logging.warning("Data len is not 25, skipping.")
-    #     return
+    if len(data) != 25:
+        #     logging.warning("Data len is not 25, skipping.")
+        return False
+    data = data[0]
 
     nose_x = data[0][0]
     nose_y = data[0][1]
@@ -134,11 +134,11 @@ def analyse_npy_side_gaotaitui(data):
 
 def analyse_npy_side_shendun(data):
     result = {}
-    data = data[0]
 
-    # if len(data) != 25:
-    #     logging.warning("Data len is not 25, skipping.")
-    #     return
+    if len(data) != 25:
+        #     logging.warning("Data len is not 25, skipping.")
+        return False
+    data = data[0]
 
     hip_r_x = data[9][0]
     hip_r_y = data[9][1]
@@ -181,7 +181,7 @@ def analyse_npy_side_jump(data):
     result = {}
     if len(data) != 25:
         # logging.warning("Data len is not 25, skipping.")
-        return {}
+        return False
 
     data = data[0]
 

+ 0 - 2
backend_refactor/service/ai/video/video_score/balancebeam.py

@@ -61,8 +61,6 @@ def cal_balancebeam(result):
     is_begin = False
     end_index = 0
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if float(result[index]["neck_centre_angle"]) > 135 and is_begin == False:
             is_begin = True
             begin_index = index

+ 0 - 10
backend_refactor/service/ai/video/video_score/jump.py

@@ -38,8 +38,6 @@ def cal_jump(result):
     initial_ankle_height = float(result[list(result.keys())[0]]["leg_heigh"])
     min_ankle_height = initial_ankle_height
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if float(result[index]["leg_heigh"]) < initial_ankle_height - 3:
             if float(result[index]["leg_heigh"]) < float(min_ankle_height) and float(
                     result[index]["leg_heigh"]) != 0.0:
@@ -50,8 +48,6 @@ def cal_jump(result):
     min_hip_angle = float(result[list(result.keys())[0]]["hip_right_angle"])
     min_wrist_index = list(result.keys())[0]
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if float(result[index]["leg_heigh"]) >= initial_ankle_height - 3:
             if float(result[index]["hip_right_angle"]) <= min_hip_angle and float(
                     result[index]["hip_right_angle"]) != 0.0:
@@ -64,8 +60,6 @@ def cal_jump(result):
         #     break
     leave_index = min_hip_angle_index
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if float(index) < float(min_hip_angle_index):
             if float(result[index]["leg_heigh"]) >= initial_ankle_height - 3:
                 if float(result[index]["wrist_heigh"]) <= min_wrist_height and float(
@@ -110,8 +104,6 @@ def cal_jump(result):
     highest_ankle_index = list(result.keys())[0]
     min_ankle_height = initial_ankle_height
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if float(index) > float(leave_index):
             if float(result[index]["leg_heigh"]) < initial_ankle_height - 3:
                 if float(result[index]["knee_right_angle"]) >= float(max_hip_angle):
@@ -148,8 +140,6 @@ def cal_jump(result):
     lowest_ankle_height = float(result[reland_index]["leg_heigh"])
     lowest_ankle_index = list(result.keys())[0]
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if int(index) <= int(highest_ankle_index):
             continue
         else:

+ 0 - 4
backend_refactor/service/ai/video/video_score/jumpwithboth.py

@@ -73,8 +73,6 @@ def cal_jumpwithboth(result):
     highest_ankle_index = list(result.keys())[0]
 
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if float(result[index]["leg_heigh"]) < float(highest_ankle) and float(
                 result[index]["leg_heigh"]) != 0.0:
             highest_ankle = float(result[index]["leg_heigh"])
@@ -93,8 +91,6 @@ def cal_jumpwithboth(result):
     ground_height = max(float(result[list(result.keys())[0]]["leg_left_heigh"]),
                         float(result[list(result.keys())[0]]["leg_right_heigh"]))
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if index == list(result.keys())[0]: continue
         if float(result[str(int(index) - 1)]["leg_heigh"]) <= float(result[index]["leg_heigh"]) and float(
                 result[index]["leg_heigh"]) >= ground_height:

+ 0 - 6
backend_refactor/service/ai/video/video_score/pingban.py

@@ -48,8 +48,6 @@ def cal_pingban(result):
     re = {}
     # clean the data
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if float(result[index]["knee_right_angle"]) == 0.0:
             result_ig[index]["knee_right_angle"] = result[index]["knee_left_angle"]
         if float(result[index]["knee_left_angle"]) == 0.0:
@@ -67,8 +65,6 @@ def cal_pingban(result):
     if is_prepared:
         lowest_knee = float(result_ig[list(result.keys())[0]]["knee_heigh"])
         for index in result:
-            if len(result[index]) == 0:
-                continue
             if float(lowest_knee) < float(result[index]["knee_heigh"]):
                 lowest_knee = result[index]["knee_heigh"]
                 first_index = index
@@ -91,8 +87,6 @@ def cal_pingban(result):
     second_pics = []
     satisfied_index = []
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if float(index) < float(first_index):
             continue
         else:

+ 0 - 2
backend_refactor/service/ai/video/video_score/sitforward.py

@@ -38,8 +38,6 @@ def cal_sitforward(result):
     highest_weist_index = list(result.keys())[0]
 
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if float(result[index]["wrist_x"]) < float(highest_wrist_x) and float(result[index]["wrist_x"]) != 0:
             highest_wrist_x = result[index]["wrist_x"]
             highest_weist_index = index

+ 0 - 4
backend_refactor/service/ai/video/video_score/standing.py

@@ -70,13 +70,9 @@ def cal_standing(result):
     minest_knee_angle_index = list(result.keys())[0]
 
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if float(result[index]["knee_right_angle"]) < 165:
             mode = "knee_right_angle"
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if float(result[index][mode]) < 168:
             if begin_index == 0:
                 begin_index = index

+ 0 - 6
backend_refactor/service/ai/video/video_score/tennisthrow.py

@@ -72,8 +72,6 @@ def cal_tennisthrow(result):
     highest_wrist = 1000
     highest_wrist_index = 0
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if float(result[index]["wrist_left_heigh"]) < float(neck_height) and float(
                 result[index]["wrist_left_heigh"]) != 0:
             print(float(result[index]["wrist_left_heigh"]))
@@ -83,8 +81,6 @@ def cal_tennisthrow(result):
     print(hand)
     # third score
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if hand == "elbow_right_angle":
             if float(result[index]["wrist_right_heigh"]) < float(highest_wrist) and float(
                     result[index]["wrist_right_heigh"]) != 0:
@@ -102,8 +98,6 @@ def cal_tennisthrow(result):
     farrest_distance_index = list(result.keys())[0]
     farrest_distance = 0
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if float(index) < float(highest_wrist_index):
             if hand == "elbow_right_angle":
                 if float(result[index]["wrist_right_distance"]) > float(farrest_distance) and float(

+ 0 - 4
backend_refactor/service/ai/video/video_score/turnaround.py

@@ -105,8 +105,6 @@ def cal_turnaround(result):
     key_index = 0
     satisfied_index = []
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if float(result[index]["foot_distance"]) > float(
                 result[list(result.keys())[key_index - 1]]["foot_distance"]) and float(
             result[index]["foot_distance"]) < float(
@@ -136,8 +134,6 @@ def cal_turnaround(result):
     lowest_midhip = 0
     lowest_midhip_index = 0
     for index in result:
-        if len(result[index]) == 0:
-            continue
         if float(lowest_midhip) < float(result[index]["midhip_heigh"]) and float(
                 result[index]["midhip_heigh"]) != 0:
             lowest_midhip = result[index]["midhip_heigh"]

+ 13 - 1
backend_refactor/service/video_analyzer.py

@@ -64,7 +64,8 @@ def run_openpose_for_npy_and_video(video_uuid, callback: Callable):
                 cv2.imwrite(UPLOAD_DIR + "result/" + video_uuid + "." + str(c) + ".jpg", canvas)
 
                 if out is None:
-                    out = cv2.VideoWriter(UPLOAD_DIR + "result/" + video_uuid + ".result.mp4", cv2.VideoWriter_fourcc(*"vp90"), FPS,
+                    out = cv2.VideoWriter(UPLOAD_DIR + "result/" + video_uuid + ".result.mp4",
+                                          cv2.VideoWriter_fourcc(*"vp90"), FPS,
                                           (canvas.shape[1], canvas.shape[0]))  # So fucking stupid
                 out.write(canvas)
 
@@ -116,6 +117,7 @@ class BaseVideoAnalyzer:
 class JumpVideoAnalyzer(BaseVideoAnalyzer):
     def _do_analyze(self):
         self.results = {k: analyse_npy_side_jump(v) for k, v in self.results.items()}
+        self.results = {k: v for k, v in self.results.items() if v != False}
         raw = cal_jump(self.results)[1]
         return classify_jump(raw)
 
@@ -123,6 +125,7 @@ class JumpVideoAnalyzer(BaseVideoAnalyzer):
 class PingbanVideoAnalyzer(BaseVideoAnalyzer):
     def _do_analyze(self):
         self.results = {k: analyse_npy_side_jump(v) for k, v in self.results.items()}
+        self.results = {k: v for k, v in self.results.items() if v != False}
         raw = cal_pingban(self.results)[1]
         return classify_pingban(raw)
 
@@ -130,6 +133,7 @@ class PingbanVideoAnalyzer(BaseVideoAnalyzer):
 class JuanfuVideoAnalyzer(BaseVideoAnalyzer):
     def _do_analyze(self):
         self.results = {k: analyse_npy_side_juanfu(v) for k, v in self.results.items()}
+        self.results = {k: v for k, v in self.results.items() if v != False}
         raw = ignore_data_juanfu(self.results)[1]
         return classify_juanfu(raw)
 
@@ -137,6 +141,7 @@ class JuanfuVideoAnalyzer(BaseVideoAnalyzer):
 class ShendunVideoAnalyzer(BaseVideoAnalyzer):
     def _do_analyze(self):
         self.results = {k: analyse_npy_side_shendun(v) for k, v in self.results.items()}
+        self.results = {k: v for k, v in self.results.items() if v != False}
         raw = ignore_data_shendun(self.results)[1]
         return classify_shendun(raw)
 
@@ -144,6 +149,7 @@ class ShendunVideoAnalyzer(BaseVideoAnalyzer):
 class GaotaituiVideoAnalyzer(BaseVideoAnalyzer):
     def _do_analyze(self):
         self.results = {k: analyse_npy_side_gaotaitui(v) for k, v in self.results.items()}
+        self.results = {k: v for k, v in self.results.items() if v != False}
         raw = ignore_data_gaotaitui(self.results)[1]
         return classify_gaotaitui(raw)
 
@@ -151,6 +157,7 @@ class GaotaituiVideoAnalyzer(BaseVideoAnalyzer):
 class TurnaroundVideoAnalyzer(BaseVideoAnalyzer):
     def _do_analyze(self):
         self.results = {k: analyse_npy_side_jump(v) for k, v in self.results.items()}
+        self.results = {k: v for k, v in self.results.items() if v != False}
         raw = cal_turnaround(self.results)[1]
         return classify_turnaround(raw)
 
@@ -158,6 +165,7 @@ class TurnaroundVideoAnalyzer(BaseVideoAnalyzer):
 class TennisthrowVideoAnalyzer(BaseVideoAnalyzer):
     def _do_analyze(self):
         self.results = {k: analyse_npy_side_jump(v) for k, v in self.results.items()}
+        self.results = {k: v for k, v in self.results.items() if v != False}
         raw = cal_tennisthrow(self.results)[1]
         return classify_tennisthrow(raw)
 
@@ -165,6 +173,7 @@ class TennisthrowVideoAnalyzer(BaseVideoAnalyzer):
 class JumpwithbothVideoAnalyzer(BaseVideoAnalyzer):
     def _do_analyze(self):
         self.results = {k: analyse_npy_side_jump(v) for k, v in self.results.items()}
+        self.results = {k: v for k, v in self.results.items() if v != False}
         raw = cal_jumpwithboth(self.results)[1]
         return classify_jumpwithboth(raw)
 
@@ -172,6 +181,7 @@ class JumpwithbothVideoAnalyzer(BaseVideoAnalyzer):
 class SitforwardVideoAnalyzer(BaseVideoAnalyzer):
     def _do_analyze(self):
         self.results = {k: analyse_npy_side_jump(v) for k, v in self.results.items()}
+        self.results = {k: v for k, v in self.results.items() if v != False}
         raw = cal_sitforward(self.results)[1]
         return classify_sitforward(raw)
 
@@ -179,6 +189,7 @@ class SitforwardVideoAnalyzer(BaseVideoAnalyzer):
 class BalancebeamVideoAnalyzer(BaseVideoAnalyzer):
     def _do_analyze(self):
         self.results = {k: analyse_npy_side_jump(v) for k, v in self.results.items()}
+        self.results = {k: v for k, v in self.results.items() if v != False}
         raw = cal_balancebeam(self.results)[1]
         return classify_balancebeam(raw)
 
@@ -186,5 +197,6 @@ class BalancebeamVideoAnalyzer(BaseVideoAnalyzer):
 class StandingVideoAnalyzer(BaseVideoAnalyzer):
     def _do_analyze(self):
         self.results = {k: analyse_npy_side_jump(v) for k, v in self.results.items()}
+        self.results = {k: v for k, v in self.results.items() if v != False}
         raw = cal_standing(self.results)[1]
         return classify_standing(raw)