def __init__(self,
              model=DEFAULT_MODEL,
              device='CPU',
              model_input_height=256,
              upsample_ratio=4,
              color_palette="openpose"):
     self.stride = 8
     self.inference_engine = InferenceEngine(model, device, self.stride)
     self.model_input_height = model_input_height
     self.upsample_ratio = upsample_ratio
     self.color_palette = color_palette
class HumanPose:
    def __init__(self,
                 model=DEFAULT_MODEL,
                 device='CPU',
                 model_input_height=256,
                 upsample_ratio=4,
                 color_palette="openpose"):
        self.stride = 8
        self.inference_engine = InferenceEngine(model, device, self.stride)
        self.model_input_height = model_input_height
        self.upsample_ratio = upsample_ratio
        self.color_palette = color_palette

    def eval(self, frame):

        input_scale = self.model_input_height / frame.shape[0]
        scaled_img = cv2.resize(frame,
                                dsize=None,
                                fx=input_scale,
                                fy=input_scale)
        # Inference
        inference_result = self.inference_engine.infer(scaled_img)
        # Postprocessing (grouping)
        poses_2d = parse_poses(inference_result, input_scale, self.stride,
                               self.upsample_ratio)  #, threshold)

        return poses_2d

    def draw(self, frame, poses_2d, draw_fps=False):
        draw_poses(frame, poses_2d, color_palette=self.color_palette)
Пример #3
0
    def __init__(self, parent, capture, height, width, counter_label, motion, fps=24):
        wx.Panel.__init__(self, parent)
        
        assert motion in ('jumpingjack','situp','squat')

        # set model parameter
        model = "human-pose-estimation-0001.xml"
        device = "CPU"
        self.base_height = 256
        self.inference_engine = InferenceEngine(model, device,8)

        # set parameter for count action          
        self.motion = motion
        self.up=False
        self.count=0

        # label for update counter 
        self.counter_label = counter_label   

        # limit size of screen
        self.width = width
        self.height = height

        # set panel size and position
        self.SetSize(width,height)
        self.SetPosition(wx.Point(50,10))

        # capture rgb frame
        self.capture = capture
        ret, rgb = self.capture.read()

        rgb = cv2.cvtColor(rgb, cv2.COLOR_BGR2RGB)
        rgb = cv2.resize(rgb, (self.width, self.height))

        self.bmp = wx.Bitmap.FromBuffer(self.width, self.height, rgb)

        self.timer = wx.Timer(self)
        self.timer.Start(1000/fps+1)

        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_TIMER, self.NextFrame)
Пример #4
0
                      default=-1,
                      help='Optional. Camera focal length.')
    args.add_argument('--no_show',
                      help='Optional. Do not display output.',
                      action='store_true')
    args.add_argument("-u",
                      "--utilization_monitors",
                      default='',
                      type=str,
                      help="Optional. List of monitors to show initially.")
    args = parser.parse_args()

    cap = open_images_capture(args.input, args.loop)

    stride = 8
    inference_engine = InferenceEngine(args.model, args.device, stride)
    canvas_3d = np.zeros((720, 1280, 3), dtype=np.uint8)
    plotter = Plotter3d(canvas_3d.shape[:2])
    canvas_3d_window_name = 'Canvas 3D'
    if not args.no_show:
        cv2.namedWindow(canvas_3d_window_name)
        cv2.setMouseCallback(canvas_3d_window_name, Plotter3d.mouse_callback)

    file_path = args.extrinsics_path
    if file_path is None:
        file_path = Path(__file__).parent / 'data/extrinsics.json'
    with open(file_path, 'r') as f:
        extrinsics = json.load(f)
    R = np.array(extrinsics['R'], dtype=np.float32)
    t = np.array(extrinsics['t'], dtype=np.float32)
Пример #5
0
class ShowCamCapture(wx.Panel):
    def __init__(self, parent, capture, height, width, counter_label, motion, fps=24):
        wx.Panel.__init__(self, parent)
        
        assert motion in ('jumpingjack','situp','squat')

        # set model parameter
        model = "human-pose-estimation-0001.xml"
        device = "CPU"
        self.base_height = 256
        self.inference_engine = InferenceEngine(model, device,8)

        # set parameter for count action          
        self.motion = motion
        self.up=False
        self.count=0

        # label for update counter 
        self.counter_label = counter_label   

        # limit size of screen
        self.width = width
        self.height = height

        # set panel size and position
        self.SetSize(width,height)
        self.SetPosition(wx.Point(50,10))

        # capture rgb frame
        self.capture = capture
        ret, rgb = self.capture.read()

        rgb = cv2.cvtColor(rgb, cv2.COLOR_BGR2RGB)
        rgb = cv2.resize(rgb, (self.width, self.height))

        self.bmp = wx.Bitmap.FromBuffer(self.width, self.height, rgb)

        self.timer = wx.Timer(self)
        self.timer.Start(1000/fps+1)

        self.Bind(wx.EVT_PAINT, self.OnPaint)
        self.Bind(wx.EVT_TIMER, self.NextFrame)


    def OnPaint(self, evt):
        dc = wx.BufferedPaintDC(self)
        dc.DrawBitmap(self.bmp, 0, 0)

    def NextFrame(self, event):
        ret, rgb = self.capture.read()
        self.counter_label.SetLabel("Times: " + str(self.count))

        if ret:
            input_scale = self.base_height / rgb.shape[0]
            scaled_img = cv2.resize(rgb, dsize=None, fx=input_scale, fy=input_scale)
            inference_result = self.inference_engine.infer(scaled_img)
            poses_2d = parse_poses(inference_result, input_scale, 8, -1, True)
            draw_poses(rgb, poses_2d)
            if self.motion=="jumpingjack":
                self.up,self.count = count_jumpup(poses_2d,self.up,self.count)
            elif self.motion=="situp":
                self.up,self.count = count_situp(poses_2d,self.up,self.count)
            elif self.motion=="squat":
                self.up,self.count = count_squat(poses_2d,self.up,self.count)
            rgb = cv2.cvtColor(rgb, cv2.COLOR_BGR2RGB)
            self.bmp.CopyFromBuffer(rgb)
            self.Refresh()
        else:
            self.timer.Stop()