|
|
@@ -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
|