示例#1
0
    def _run_net(self):
        # inference
        hm, xm, ym, zm = self.sess.run([self.heatmap, self.x_heatmap, self.y_heatmap, self.z_heatmap],
                                       {self.input_crops: self.input_batch})

        # average scale outputs
        hm_size = self.box_size // self.hm_factor
        hm_avg = np.zeros((hm_size, hm_size, self.joints_num))
        xm_avg = np.zeros((hm_size, hm_size, self.joints_num))
        ym_avg = np.zeros((hm_size, hm_size, self.joints_num))
        zm_avg = np.zeros((hm_size, hm_size, self.joints_num))
        for i in range(len(self.scales)):
            rescale = 1.0 / self.scales[i]
            scaled_hm = utils.img_scale(hm[i, :, :, :], rescale)
            scaled_x_hm = utils.img_scale(xm[i, :, :, :], rescale)
            scaled_y_hm = utils.img_scale(ym[i, :, :, :], rescale)
            scaled_z_hm = utils.img_scale(zm[i, :, :, :], rescale)
            mid = [scaled_hm.shape[0] // 2, scaled_hm.shape[1] // 2]
            hm_avg += scaled_hm[mid[0] - hm_size//2: mid[0] + hm_size//2, mid[1] - hm_size//2: mid[1] + hm_size//2, :]
            xm_avg += scaled_x_hm[mid[0] - hm_size//2: mid[0] + hm_size//2, mid[1] - hm_size//2: mid[1] + hm_size//2, :]
            ym_avg += scaled_y_hm[mid[0] - hm_size//2: mid[0] + hm_size//2, mid[1] - hm_size//2: mid[1] + hm_size//2, :]
            zm_avg += scaled_z_hm[mid[0] - hm_size//2: mid[0] + hm_size//2, mid[1] - hm_size//2: mid[1] + hm_size//2, :]

        hm_avg /= len(self.scales)
        xm_avg /= len(self.scales)
        ym_avg /= len(self.scales)
        zm_avg /= len(self.scales)

        self.joints_2d = utils.extract_2d_joints_from_heatmap(hm_avg, self.box_size, self.hm_factor)
        self.joints_3d = utils.extract_3d_joints_from_heatmap(self.joints_2d, xm_avg, ym_avg, zm_avg, self.box_size,
                                                              self.hm_factor)
示例#2
0
def main(q_start3d, q_joints):
    init()
    x, y, w, h = hog_box()
    q_start3d.put(True)
    success, frame = camera_capture.read()
    while success and cv2.waitKey(1) == -1:
        if T:
            # mirror
            # frame = np.transpose(frame, axes=[1, 0, 2])
            # no mirror
            frame = np.rot90(frame, 3)
        # crop bounding box from the raw frame
        frame_cropped = frame[y:y + h, x:x + w, :]
        # vnect estimation
        joints_2d, joints_3d = estimator(frame_cropped)
        q_joints.put(joints_3d)
        # 2d plotting
        joints_2d[:, 0] += y
        joints_2d[:, 1] += x
        frame_draw = utils.draw_limbs_2d(frame.copy(), joints_2d,
                                         joint_parents, [x, y, w, h])
        frame_draw = utils.img_scale(frame_draw, 1024 / max(W_img, H_img))
        cv2.imshow('2D Prediction', frame_draw)
        # update bounding box
        y_min = (np.min(joints_2d[:, 0]))
        y_max = (np.max(joints_2d[:, 0]))
        x_min = (np.min(joints_2d[:, 1]))
        x_max = (np.max(joints_2d[:, 1]))
        buffer_x = 0.8 * (x_max - x_min + 1)
        buffer_y = 0.2 * (y_max - y_min + 1)
        x, y = (max(int(x_min - buffer_x / 2),
                    0), max(int(y_min - buffer_y / 2), 0))
        w, h = (int(min(x_max - x_min + buffer_x, W_img - x)),
                int(min(y_max - y_min + buffer_y, H_img - y)))
        # update frame
        success, frame = camera_capture.read()

    # angles_file.close()
    try:
        camera_capture.release()
        cv2.destroyAllWindows()
    except Exception as e:
        print(e)
        raise
示例#3
0
success, frame = camera_capture.read()
while success and cv2.waitKey(1) == -1:
    if T:
        # mirror
        # frame = np.transpose(frame, axes=[1, 0, 2])
        # no mirror
        frame = np.rot90(frame, 3)
    # crop bounding box from the raw frame
    frame_cropped = frame[y: y + h, x: x + w, :]
    # vnect estimation
    joints_2d, joints_3d = estimator(frame_cropped)
    # 2d plotting
    joints_2d[:, 0] += y
    joints_2d[:, 1] += x
    frame_draw = utils.draw_limbs_2d(frame.copy(), joints_2d, joint_parents, [x, y, w, h])
    frame_draw = utils.img_scale(frame_draw, 1024 / max(W_img, H_img))
    cv2.imshow('2D Prediction', frame_draw)
    # update bounding box
    y_min = (np.min(joints_2d[:, 0]))
    y_max = (np.max(joints_2d[:, 0]))
    x_min = (np.min(joints_2d[:, 1]))
    x_max = (np.max(joints_2d[:, 1]))
    buffer_x = 0.8 * (x_max - x_min + 1)
    buffer_y = 0.2 * (y_max - y_min + 1)
    x, y = (max(int(x_min - buffer_x / 2), 0),
            max(int(y_min - buffer_y / 2), 0))
    w, h = (int(min(x_max - x_min + buffer_x, W_img - x)),
            int(min(y_max - y_min + buffer_y, H_img - y)))
    # update frame
    success, frame = camera_capture.read()