|
|
@@ -5,20 +5,20 @@ from typing import Callable
|
|
|
|
|
|
import cv2
|
|
|
|
|
|
-from config import UPLOAD_DIR
|
|
|
+from config import UPLOAD_DIR, FILE_URL
|
|
|
from service.ai.util.torch_openpose import torch_openpose
|
|
|
from service.ai.util.util import draw_bodypose
|
|
|
+from service.ai.video.classify.balancebeam import classify_balancebeam
|
|
|
from service.ai.video.classify.gaotaitui import classify_gaotaitui
|
|
|
from service.ai.video.classify.juanfu import classify_juanfu
|
|
|
-from service.ai.video.classify.shendun import classify_shendun
|
|
|
-from service.ai.video.classify.turnaround import classify_turnaround
|
|
|
-from service.ai.video.classify.standing import classify_standing
|
|
|
-from service.ai.video.classify.pingban import classify_pingban
|
|
|
-from service.ai.video.classify.balancebeam import classify_balancebeam
|
|
|
from service.ai.video.classify.jump import classify_jump
|
|
|
from service.ai.video.classify.jumpwithboth import classify_jumpwithboth
|
|
|
+from service.ai.video.classify.pingban import classify_pingban
|
|
|
+from service.ai.video.classify.shendun import classify_shendun
|
|
|
from service.ai.video.classify.sitforward import classify_sitforward
|
|
|
+from service.ai.video.classify.standing import classify_standing
|
|
|
from service.ai.video.classify.tennisthrow import classify_tennisthrow
|
|
|
+from service.ai.video.classify.turnaround import classify_turnaround
|
|
|
from service.ai.video.inner_analyze import analyse_npy_side_jump, analyse_npy_side_juanfu, analyse_npy_side_shendun, \
|
|
|
analyse_npy_side_gaotaitui
|
|
|
from service.ai.video.video_score.balancebeam import cal_balancebeam
|
|
|
@@ -61,14 +61,16 @@ def run_openpose_for_npy_and_video(video_uuid, callback: Callable):
|
|
|
results[str(c)] = poses # this is evil, but the AI code expect it to be so.
|
|
|
|
|
|
canvas = draw_bodypose(frame, poses, 'body_25')
|
|
|
+ cv2.imwrite(UPLOAD_DIR + "result/" + video_uuid + "." + str(c) + ".jpg", canvas)
|
|
|
|
|
|
if out is None:
|
|
|
- out = cv2.VideoWriter(UPLOAD_DIR + video_uuid + ".result.mp4", cv2.VideoWriter_fourcc(*"mp4v"), 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)
|
|
|
|
|
|
c += 1
|
|
|
- callback("RUNNING", progress=min(99,int(100*c/(total_frames/sampling_fps))))
|
|
|
+ callback("RUNNING", progress=min(99, int(100 * c / (total_frames / sampling_fps))))
|
|
|
else:
|
|
|
break
|
|
|
|
|
|
@@ -98,7 +100,15 @@ class BaseVideoAnalyzer:
|
|
|
else: # read cache
|
|
|
self.results = pickle.load(open(PICKLE_DUMP_PATH, "rb"))
|
|
|
|
|
|
- callback("FINISHED", result=self._do_analyze())
|
|
|
+ result = {**self._do_analyze(), "file": FILE_URL + self.video_uuid + ".result.mp4"}
|
|
|
+ # inject file url here
|
|
|
+ try:
|
|
|
+ for i in result['data']:
|
|
|
+ result['data'][i]['file'] = FILE_URL + self.video_uuid + "." + result['data'][i]['index'] + ".jpg"
|
|
|
+ except Exception as e:
|
|
|
+ logging.warning("file index in data not found, %s" % e)
|
|
|
+
|
|
|
+ callback("FINISHED", result=result)
|
|
|
except Exception as e:
|
|
|
callback("ERROR", error=e)
|
|
|
raise e
|
|
|
@@ -107,75 +117,77 @@ 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 != {}}
|
|
|
raw = cal_jump(self.results)[1]
|
|
|
- return {"raw": raw, "analysis": classify_jump(raw)}
|
|
|
+ return classify_jump(raw)
|
|
|
|
|
|
|
|
|
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 != {}}
|
|
|
raw = cal_pingban(self.results)[1]
|
|
|
- return {"raw": raw, "analysis": classify_pingban(raw)}
|
|
|
+ return classify_pingban(raw)
|
|
|
|
|
|
|
|
|
class JuanfuVideoAnalyzer(BaseVideoAnalyzer):
|
|
|
def _do_analyze(self):
|
|
|
self.results = {k: analyse_npy_side_juanfu(v) for k, v in self.results.items()}
|
|
|
raw = ignore_data_juanfu(self.results)[1]
|
|
|
- return {"raw": raw, "analysis": classify_juanfu(raw)}
|
|
|
+ return classify_juanfu(raw)
|
|
|
|
|
|
|
|
|
class ShendunVideoAnalyzer(BaseVideoAnalyzer):
|
|
|
def _do_analyze(self):
|
|
|
self.results = {k: analyse_npy_side_shendun(v) for k, v in self.results.items()}
|
|
|
raw = ignore_data_shendun(self.results)[1]
|
|
|
- return {"raw": raw, "analysis": classify_shendun(raw)}
|
|
|
+ return classify_shendun(raw)
|
|
|
|
|
|
|
|
|
class GaotaituiVideoAnalyzer(BaseVideoAnalyzer):
|
|
|
def _do_analyze(self):
|
|
|
self.results = {k: analyse_npy_side_gaotaitui(v) for k, v in self.results.items()}
|
|
|
raw = ignore_data_gaotaitui(self.results)[1]
|
|
|
- return {"raw": raw, "analysis": classify_gaotaitui(raw)}
|
|
|
+ return classify_gaotaitui(raw)
|
|
|
|
|
|
|
|
|
class TurnaroundVideoAnalyzer(BaseVideoAnalyzer):
|
|
|
def _do_analyze(self):
|
|
|
self.results = {k: analyse_npy_side_jump(v) for k, v in self.results.items()}
|
|
|
raw = cal_turnaround(self.results)[1]
|
|
|
- return {"raw": raw, "analysis": classify_turnaround(raw)}
|
|
|
+ return classify_turnaround(raw)
|
|
|
|
|
|
|
|
|
class TennisthrowVideoAnalyzer(BaseVideoAnalyzer):
|
|
|
def _do_analyze(self):
|
|
|
self.results = {k: analyse_npy_side_jump(v) for k, v in self.results.items()}
|
|
|
raw = cal_tennisthrow(self.results)[1]
|
|
|
- return {"raw": raw, "analysis": classify_tennisthrow(raw)}
|
|
|
+ return classify_tennisthrow(raw)
|
|
|
|
|
|
|
|
|
class JumpwithbothVideoAnalyzer(BaseVideoAnalyzer):
|
|
|
def _do_analyze(self):
|
|
|
self.results = {k: analyse_npy_side_jump(v) for k, v in self.results.items()}
|
|
|
raw = cal_jumpwithboth(self.results)[1]
|
|
|
- return {"raw": raw, "analysis": classify_jumpwithboth(raw)}
|
|
|
+ return classify_jumpwithboth(raw)
|
|
|
|
|
|
|
|
|
class SitforwardVideoAnalyzer(BaseVideoAnalyzer):
|
|
|
def _do_analyze(self):
|
|
|
self.results = {k: analyse_npy_side_jump(v) for k, v in self.results.items()}
|
|
|
raw = cal_sitforward(self.results)[1]
|
|
|
- return {"raw": raw, "analysis": classify_sitforward(raw)}
|
|
|
+ return classify_sitforward(raw)
|
|
|
|
|
|
|
|
|
class BalancebeamVideoAnalyzer(BaseVideoAnalyzer):
|
|
|
def _do_analyze(self):
|
|
|
self.results = {k: analyse_npy_side_jump(v) for k, v in self.results.items()}
|
|
|
raw = cal_balancebeam(self.results)[1]
|
|
|
- return {"raw": raw, "analysis": classify_balancebeam(raw)}
|
|
|
+ return classify_balancebeam(raw)
|
|
|
|
|
|
|
|
|
class StandingVideoAnalyzer(BaseVideoAnalyzer):
|
|
|
def _do_analyze(self):
|
|
|
self.results = {k: analyse_npy_side_jump(v) for k, v in self.results.items()}
|
|
|
raw = cal_standing(self.results)[1]
|
|
|
- return {"raw": raw, "analysis": classify_standing(raw)}
|
|
|
+ return classify_standing(raw)
|