Parcourir la source

Merge branch 'dev' of http://gogs.seec.seecoder.cn/ZhaoFengShan/PoseCorrection into dev

LeoDu il y a 4 ans
Parent
commit
bf6c7f8998

+ 7 - 0
backend_refactor/app.py

@@ -21,6 +21,7 @@ with app.app_context():
     # db.drop_all()
     db.create_all()
 
+
 @app.route("/")
 def hello_world():
     return "<p>Hello, World!</p>"
@@ -35,6 +36,12 @@ def error_handler(e):
     return make_response(413, "entity too large, max acceptable: " + str(MAX_CONTENT_LENGTH) + " bytes", {})
 
 
+@app.errorhandler(404)
+def error_handler(e):
+    logging.exception(e)
+    return make_response(404, "path not found.", {})
+
+
 @app.errorhandler(Exception)
 def error_handler(e):
     logging.exception(e)

+ 0 - 2
backend_refactor/config/__init__.py

@@ -5,5 +5,3 @@ UPLOAD_DIR = "/data/"
 MAX_CONTENT_LENGTH = 100 * 1024 * 1024
 
 MYSQL_URI = f'mysql://{os.environ["MYSQL_USER"]}:{os.environ["MYSQL_PASSWORD"]}@{os.environ["MYSQL_ADDRESS"]}/{os.environ["MYSQL_DATABASE"]}'
-
-CACHE_DIR = "/tmp/"

+ 3 - 0
backend_refactor/service/photo/BasePhotoAnalyzer.py

@@ -0,0 +1,3 @@
+class BasePhotoAnalyzer:
+    def __init__(self):
+        pass

+ 22 - 30
backend_refactor/service/photo/StandingPhotoAnalyzer.py

@@ -1,4 +1,3 @@
-
 from service.photo import BasePhotoAnalyzer
 
 import cv2
@@ -7,47 +6,40 @@ import copy
 import numpy as np
 from PIL import Image
 import os
-# from config import CACHE_DIR
 
-CACHE_DIR = "/tmp/"
+from config import UPLOAD_DIR
 
 import service.photo.src1.util2 as util
 from service.photo.src1.body import Body
 from service.photo.src1.torch_openpose import torch_openpose
 import service.photo.src1 as src1
-# from src.infer_video_d2 import infer_image,load_predictor
-# from video_pose.inference.infer_video_d2 import run_3d
-# from video_pose.data.prepare_data_2d_custom import custom
-# from video_pose.run import run_video_reconstruction
-
-
-
-class StandingPhotoAnalyzer():
-
-    def analyze(self, *args):
 
-        assert len(args) == 2, "Invalid arguments: expect 2 photo uuids."
 
-        for i in args:
-            test_image = CACHE_DIR + '{}.jpg'.format(i)
+class StandingPhotoAnalyzer(BasePhotoAnalyzer):
 
-            oriImg = cv2.imread(test_image)  # B,G,R order
-
-            tp = torch_openpose('body_25')
-            poses = tp(oriImg)
-
-            np.save(CACHE_DIR + '{}.npy'.format(i), poses)
+    def __init__(self, *args):
+        super().__init__()
+        assert len(self.args) == 2, "Invalid arguments: expect 2 photo uuids."
+        self.args = args
 
-            canvas = copy.deepcopy(oriImg)
-            canvas = src1.util.draw_bodypose(canvas, poses, 'body_25')
+    def analyze(self, callback: function) -> None:
+        callback("RUNNING")
+        try:
+            for i in self.args:
+                test_image = UPLOAD_DIR + '{}.jpg'.format(i)
 
-            cv2.imwrite(CACHE_DIR + '{}-result.jpg'.format(i), canvas)
+                ori_img = cv2.imread(test_image)  # B,G,R order
 
-    def __init__(self) -> None:
-        super().__init__()
+                tp = torch_openpose('body_25')
+                poses = tp(ori_img)
 
+                np.save(UPLOAD_DIR + '{}.npy'.format(i), poses)
 
+                canvas = copy.deepcopy(ori_img)
+                canvas = src1.util.draw_bodypose(canvas, poses, 'body_25')
 
-if __name__ == "__main__":
-    ana = StandingPhotoAnalyzer()
-    ana.analyze("1", "2")
+                cv2.imwrite(UPLOAD_DIR + '{}-result.jpg'.format(i), canvas)
+                callback("FINISH", result={"photos": {}, "text": {}})
+        except Exception as e:
+            callback("ERROR", error=e)
+            raise e