43 lines
1.6 KiB
Python
43 lines
1.6 KiB
Python
|
from copy import deepcopy, copy
|
||
|
|
||
|
import numpy as np
|
||
|
|
||
|
from DeviceDefine.consensus import UNKNOWN
|
||
|
from MCamera.mn_algorithm import MoveNetAlgorithmPlugin
|
||
|
from MCamera.mp_algorithm import MediapipeAlgorithmPlugin
|
||
|
from MCamera.mp_camera import Camera
|
||
|
from PureBackend.base_driver import MODEL_MEDIAPIPE, MODEL_MOVE_NET
|
||
|
from PureBackend.exam_driver import ExamDriver
|
||
|
|
||
|
|
||
|
def base_detect_image(camera: Camera, model):
|
||
|
if model == MODEL_MEDIAPIPE:
|
||
|
_map = MediapipeAlgorithmPlugin()
|
||
|
_img = deepcopy(camera.get_frame())
|
||
|
img = _map.find_pose_with_drawing(_img, True)
|
||
|
elif model == MODEL_MOVE_NET:
|
||
|
_map = MoveNetAlgorithmPlugin()
|
||
|
_img = deepcopy(camera.get_frame())
|
||
|
img = _map.find_pose_with_drawing(_img, True)
|
||
|
return img
|
||
|
|
||
|
|
||
|
class CameraBackend(ExamDriver):
|
||
|
|
||
|
def __init__(self, master_mode=True, positioning=True, camera=True, model=MODEL_MEDIAPIPE, speaker=True,
|
||
|
multi_positioning_mode=True, device_type=UNKNOWN, pure_mode=False):
|
||
|
super().__init__(master_mode, positioning, camera, model, speaker, multi_positioning_mode, device_type, pure_mode)
|
||
|
self.model = model
|
||
|
|
||
|
def get_exercise_video(self):
|
||
|
if self.project is None:
|
||
|
video_response = base_detect_image(self.camera, model=self.model)
|
||
|
elif self.project and not self.project.is_start:
|
||
|
video_response = self.project.pure_video_gen()
|
||
|
else:
|
||
|
video_response = self.project.pure_streaming_gen()
|
||
|
if video_response is None:
|
||
|
video_response = base_detect_image(self.camera, model=self.model)
|
||
|
frame = np.array(copy(video_response))
|
||
|
return frame
|