LeoDu 4 лет назад
Родитель
Сommit
951858cfbf

+ 6 - 1
backend_refactor/Dockerfile

@@ -7,16 +7,21 @@ WORKDIR /pose
 RUN sed -i 's/archive.ubuntu.com/mirrors.nju.edu.cn/g' /etc/apt/sources.list && \ 
     sed -i 's/security.ubuntu.com/mirrors.nju.edu.cn/g' /etc/apt/sources.list && \
     apt update && \
-    apt install -y libgl1-mesa-glx libglib2.0-dev python3-mysqldb && \
+    apt install -y libgl1-mesa-glx libglib2.0-dev libmysqlclient-dev && \
     rm -rf /var/lib/apt/lists/*
 
+
 COPY requirements.txt .
 RUN pip3 install --no-cache-dir -i https://mirror.nju.edu.cn/pypi/web/simple -r requirements.txt
 # RUN python -m pip install detectron2 --no-cache-dir -i https://mirror.nju.edu.cn/pypi/web/simple -f https://dl.fbaipublicfiles.com/detectron2/wheels/cpu/torch1.10/index.html
 
+
+
+
 VOLUME /data
 
 COPY . .
 
 CMD ["gunicorn", "app:app"]
 
+

+ 2 - 1
backend_refactor/requirements.txt

@@ -5,4 +5,5 @@ numpy==1.21.6
 opencv-python==4.6.0.66
 matplotlib==3.5.3
 scipy==1.7.3
-flask_sqlalchemy==2.5.1
+flask_sqlalchemy==2.5.1
+mysqlclient==1.4.6

+ 9 - 6
backend_refactor/route/analyze.py

@@ -1,18 +1,19 @@
 import uuid, json
-from service.video.Video3DAnalyzer import Video3DAnalyzer
+# from service.video.Video3DAnalyzer import Video3DAnalyzer
 from db import db
 from flask import request
 from db.task import Task
 from worker.thread_pool import pool
 from route.util import make_response
 from flask import Blueprint
-from service.photo import StandingPhotoAnalyzer
+from service.photo.StandingPhotoAnalyzer import StandingPhotoAnalyzer
 
 
 bp = Blueprint("analyze", __name__, url_prefix='/')
 
 def callback_generator(task_uuid):
     def callback(status, **args):
+        print("caling back")
         task = Task.query.get(task_uuid)
         task.status = status
         if status == 'FINISHED':
@@ -31,12 +32,14 @@ def photo_analysis():
     
     ana = StandingPhotoAnalyzer(req['front'], req['right'])
 
-    task_uuid = str(uuid.uuid4)
+    task_uuid = str(uuid.uuid4())
     new_task = Task(task_uuid, 'PHOTO_STANDINGPOSE')
     db.session.add(new_task)
     db.session.commit()
 
-    pool.submit(ana.analyze, (callback_generator(task_uuid), ))
+    ana.analyze(callback_generator(task_uuid))
+
+    # pool.submit(ana.analyze, (callback_generator(task_uuid), ))
 
     return make_response(201, "success", {'task_uuid' : task_uuid})
 
@@ -44,9 +47,9 @@ def photo_analysis():
 def video_analysis():
     req = request.get_json()
     
-    ana_3d = Video3DAnalyzer()
+    # ana_3d = Video3DAnalyzer()
 
-    task_uuid = str(uuid.uuid4)
+    task_uuid = str(uuid.uuid4())
     new_task = Task(task_uuid, req['type'])
     db.session.add(new_task)
     db.session.commit()

+ 4 - 3
backend_refactor/route/result.py

@@ -3,10 +3,10 @@ from flask import Blueprint
 from route.util import make_response
 from db.task import Task
 
-bp = Blueprint("result", __name__, url_prefix='/result')
+bp = Blueprint("result", __name__, url_prefix='/')
 
 
-@bp.route("/{task_uuid}", methods=["GET"])
+@bp.route("/result/<task_uuid>", methods=["GET"])
 def get_result(task_uuid):
 
     task = Task.query.get(task_uuid)
@@ -20,4 +20,5 @@ def get_result(task_uuid):
         return make_response(200, "running", {"task_uuid" : task.uuid, "type" : task.type})
     elif status == 'ERROR':
         return make_response(200, "error", {"task_uuid" : task.uuid, "type" : task.type, "result" : task.result})
-
+    else:
+        assert 0.1 + 0.2 == 0.3,  "what do u mean?"

+ 2 - 2
backend_refactor/service/photo/StandingPhotoAnalyzer.py

@@ -20,7 +20,7 @@ class StandingPhotoAnalyzer(BasePhotoAnalyzer):
 
     def __init__(self, *args):
         super().__init__()
-        assert len(self.args) == 2, "Invalid arguments: expect 2 photo uuids."
+        assert len(args) == 2, "Invalid arguments: expect 2 photo uuids."
         self.args = args
 
     def analyze(self, callback: Callable) -> None:
@@ -40,7 +40,7 @@ class StandingPhotoAnalyzer(BasePhotoAnalyzer):
                 canvas = src1.util.draw_bodypose(canvas, poses, 'body_25')
 
                 cv2.imwrite(UPLOAD_DIR + '{}-result.jpg'.format(i), canvas)
-                callback("FINISH", result={"photos": {}, "text": {}})
+                callback("FINISHED", result={"photos": {}, "text": {}})
         except Exception as e:
             callback("ERROR", error=e)
             raise e