소스 검색

elegance is not optional.

lyc8503 4 년 전
부모
커밋
b4efd33d0a
1개의 변경된 파일15개의 추가작업 그리고 57개의 파일을 삭제
  1. 15 57
      backend_refactor/service/video_analyzer.py

+ 15 - 57
backend_refactor/service/video_analyzer.py

@@ -46,6 +46,7 @@ def run_openpose_for_frames(video_uuid):
     for i in os.listdir(frames_dir):
         if i.endswith(".jpg") and "result" not in i:
 
+            # Already processed
             if os.path.exists(frames_dir + i.replace(".jpg", ".result.jpg")) and os.path.exists(
                     frames_dir + i + ".npy"):
                 continue
@@ -57,7 +58,6 @@ def run_openpose_for_frames(video_uuid):
             np.save(frames_dir + i + ".npy", poses)
 
             canvas = draw_bodypose(oriImg, poses, 'body_25')
-
             cv2.imwrite(frames_dir + i.replace(".jpg", ".result.jpg"), canvas)
 
 
@@ -65,82 +65,40 @@ class BaseVideoAnalyzer:
     def __init__(self, video_uuid):
         self.video_uuid = video_uuid
 
+    def _do_analyze(self):
+        assert False, "Internal error: You should override this with a subclass!"
+
     def analyze(self, callback: Callable):
         try:
             callback("RUNNING")
             split_video(self.video_uuid)
             run_openpose_for_frames(self.video_uuid)
-            callback("FINISHED", result={})
+            callback("FINISHED", result=self._do_analyze())
         except Exception as e:
             callback("ERROR", error=e)
             raise e
 
 
 class HighKneesVideoAnalyzer(BaseVideoAnalyzer):
-    def __init__(self, video_uuid):
-        super().__init__(video_uuid)
-
-    def analyze(self, callback: Callable):
-        try:
-            callback("RUNNING")
-
-            callback("FINISHED", result={})
-        except Exception as e:
-            callback("ERROR", error=e)
-            raise e
+    def _do_analyze(self):
+        pass
 
 
 class CrunchVideoAnalyzer(BaseVideoAnalyzer):
-    def __init__(self, video_uuid):
-        super().__init__(video_uuid)
-
-    def analyze(self, callback: Callable):
-        try:
-            callback("RUNNING")
-
-            callback("FINISHED", result={})
-        except Exception as e:
-            callback("ERROR", error=e)
-            raise e
+    def _do_analyze(self):
+        pass
 
 
 class StandingLongJumpVideoAnalyzer(BaseVideoAnalyzer):
-    def __init__(self, video_uuid):
-        super().__init__(video_uuid)
-
-    def analyze(self, callback: Callable):
-        try:
-            callback("RUNNING")
-
-            callback("FINISHED", result={})
-        except Exception as e:
-            callback("ERROR", error=e)
-            raise e
+    def _do_analyze(self):
+        pass
 
 
 class PlankVideoAnalyzer(BaseVideoAnalyzer):
-    def __init__(self, video_uuid):
-        super().__init__(video_uuid)
-
-    def analyze(self, callback: Callable):
-        try:
-            callback("RUNNING")
-
-            callback("FINISHED", result={})
-        except Exception as e:
-            callback("ERROR", error=e)
-            raise e
+    def _do_analyze(self):
+        pass
 
 
 class SquatVideoAnalyzer(BaseVideoAnalyzer):
-    def __init__(self, video_uuid):
-        super().__init__(video_uuid)
-
-    def analyze(self, callback: Callable):
-        try:
-            callback("RUNNING")
-
-            callback("FINISHED", result={})
-        except Exception as e:
-            callback("ERROR", error=e)
-            raise e
+    def _do_analyze(self):
+        pass