コード例 #1
0
def create_camera_matrix():
    """
    All parameters are taken from https://github.com/guiggh/hand_pose_action
    """

    # camera parameter for image sensor
    # Image center
    u0 = 935.732544
    v0 = 540.681030
    # Focal Length
    fx = 1395.749023
    fy = 1395.749268

    rgb_camera_intr = camera.CameraIntr(**{
        "u0": u0,
        "v0": v0,
        "fx": fx,
        "fy": fy
    })

    # camera parameter for depth sensor
    # Image center:
    depth_u0 = 315.944855
    depth_v0 = 245.287079
    # Focal Length:
    depth_fx = 475.065948
    depth_fy = 475.065857

    depth_camera_intr = camera.CameraIntr(**{
        "u0": depth_u0,
        "v0": depth_v0,
        "fx": depth_fx,
        "fy": depth_fy
    })

    # Extrinsic parameters
    # Rotations
    R = np.array([
        [0.999988496304, -0.00468848412856, 0.000982563360594],
        [0.00469115935266, 0.999985218048, -0.00273845880292],
        [-0.000969709653873, 0.00274303671904, 0.99999576807],
    ])
    # Translate
    t = np.array([25.7, 1.22, 3.902])

    camera_extr = camera.CameraExtr(R, t)

    cameras = {}
    cameras["rgb_camera_intr"] = rgb_camera_intr
    cameras["depth_camera_intr"] = depth_camera_intr
    cameras["camera_extr"] = camera_extr
    return cameras
コード例 #2
0
 def load_annotations(self, dataset_dir, debug=False):
     logger.info("load annotations mode = {}".format(self.mode))
     logger.info("dataset_dir = {}".format(dataset_dir))
     annotations = []
     with open(os.path.join(dataset_dir, "training_xyz.json"), 'r') as f:
         joint_annotations = json.load(f)
     with open(os.path.join(dataset_dir, "training_K.json"), 'r') as f:
         camera_annotations = json.load(f)
     global VAL_LIST
     VAL_LIST = np.random.choice(len(joint_annotations),
                                 int(0.1 * len(joint_annotations)))
     for idx in range(len(joint_annotations)):
         if self.mode == "train" and idx in VAL_LIST:
             continue
         if self.mode != "train" and idx not in VAL_LIST:
             continue
         rgb_joint = np.array(joint_annotations[idx])
         [[fx, _, u0], [_, fy, v0], [_, _, _]] = camera_annotations[idx]
         rgb_camera = camera.CameraIntr(u0=u0, v0=v0, fx=fx, fy=fy)
         if DATA_CONVENTION == "ZYX":
             rgb_joint = rgb_joint[:, ::-1]
             rgb_joint = rgb_joint[INDEX_CONVERTER]
         rgb_path = os.path.join(dataset_dir, "training", "rgb",
                                 "{:08d}.jpg".format(idx))
         rgb_joint = rgb_joint[INDEX_CONVERTER]
         rgb_joint = wrist2palm(rgb_joint)
         example = {}
         example["hand_side"] = "right"
         example["rgb_path"] = rgb_path
         example["rgb_joint"] = 1000 * rgb_joint
         example["rgb_camera"] = rgb_camera
         annotations.append(example)
         if debug and len(annotations) > 10:
             break
     return annotations
コード例 #3
0
def create_camera_mat():
    # These values are Taken from anno_all["K"]
    fx = fy = 283.1
    u0 = v0 = 160.
    rgb_camera_intr = camera.CameraIntr(**{
        "u0": u0,
        "v0": v0,
        "fx": fx,
        "fy": fy
    })
    depth_camera_intr = camera.CameraIntr(**{
        "u0": u0,
        "v0": v0,
        "fx": fx,
        "fy": fy
    })
    cameras = {}
    # Both, rgb and depth, have same camera parameter
    cameras["rgb_camera_intr"] = rgb_camera_intr
    cameras["depth_camera_intr"] = depth_camera_intr
    return cameras
コード例 #4
0
def create_camera_mat():
    fx = 614.878
    fy = 615.479
    u0 = 313.219
    v0 = 231.288
    rgb_camera_intr = camera.CameraIntr(**{
        "u0": u0,
        "v0": v0,
        "fx": fx,
        "fy": fy
    })
    cameras = {"rgb_camera_intr": rgb_camera_intr}
    return cameras
コード例 #5
0
def create_camera_mat():
    fx = fy = 617.173
    u0 = 315.453
    v0 = 242.259
    rgb_camera_intr = camera.CameraIntr(**{
        "u0": u0,
        "v0": v0,
        "fx": fx,
        "fy": fy
    })
    fx = fy = 475.62
    u0 = 311.125
    v0 = 245.965
    depth_camera_intr = camera.CameraIntr(**{
        "u0": u0,
        "v0": v0,
        "fx": fx,
        "fy": fy
    })

    cameras = {}
    cameras["rgb_camera_intr"] = rgb_camera_intr
    cameras["depth_camera_intr"] = depth_camera_intr
    return cameras
コード例 #6
0
def create_camera_mat():
    # See README.txt
    camera_intr = np.array([
        [617.173, 0, 315.453],
        [0, 617.173, 242.259],
        [0, 0, 1],
    ])

    fx = fy = 617.173
    u0 = 315.453
    v0 = 242.259

    rgb_camera_intr = camera.CameraIntr(**{
        "u0": u0,
        "v0": v0,
        "fx": fx,
        "fy": fy
    })
    cameras = {}
    cameras["rgb_camera_intr"] = rgb_camera_intr
    return cameras
コード例 #7
0
def create_camera_mat():
    """
    Camera parameter of Intel Real Sense F200 active depth camera.
    These parameters are taken from readme.txt of STB dataset.
    1. Camera parameters
    (1) Point Grey Bumblebee2 stereo camera:
    base line = 120.054
    fx = 822.79041
    fy = 822.79041
    tx = 318.47345
    ty = 250.31296
    (2) Intel Real Sense F200 active depth camera:
    fx color = 607.92271
    fy color = 607.88192
    tx color = 314.78337
    ty color = 236.42484
    fx depth = 475.62768
    fy depth = 474.77709
    tx depth = 336.41179
    ty depth = 238.77962
    rotation vector = [0.00531   -0.01196  0.00301] (use Rodrigues' rotation formula to transform it into rotation matrix)
    translation vector = [-24.0381   -0.4563   -1.2326]
    (rotation and translation vector can transform the coordinates relative to color camera to those relative to depth camera)
    """
    fx_color = 607.92271
    fy_color = 607.88192
    tx_color = 314.78337
    ty_color = 236.42484
    rgb_camera_intr = camera.CameraIntr(**{
        "u0": tx_color,
        "v0": ty_color,
        "fx": fx_color,
        "fy": fy_color
    })

    fx_depth = 475.62768
    fy_depth = 474.77709
    tx_depth = 336.41179
    ty_depth = 238.77962
    depth_camera_intr = camera.CameraIntr(**{
        "u0": tx_depth,
        "v0": ty_depth,
        "fx": fx_depth,
        "fy": fy_depth
    })

    def Rodrigues(rotation_vector):
        theta = np.linalg.norm(rotation_vector)
        rv = rotation_vector / theta
        rr = np.array([[rv[i] * rv[j] for j in range(3)] for i in range(3)])
        R = np.cos(theta) * np.eye(3)
        R += (1 - np.cos(theta)) * rr
        R += np.sin(theta) * np.array([
            [0, -rv[2], rv[1]],
            [rv[2], 0, -rv[0]],
            [-rv[1], rv[0], 0],
        ])
        return R

    rotation_vector = np.array([0.00531, -0.01196, 0.00301])
    R = Rodrigues(rotation_vector)
    # transpose to fit our camera class interface
    R = R.transpose()
    # apply minus to fit our camera class interface
    translation_vector = -np.array([-24.0381, -0.4563, -1.2326])
    rgb_camera_extr = camera.CameraExtr(R, translation_vector)
    depth_camera_extr = camera.CameraExtr(R, np.zeros(3))
    cameras = {}
    cameras["rgb_camera_intr"] = rgb_camera_intr
    cameras["depth_camera_intr"] = depth_camera_intr
    cameras["rgb_camera_extr"] = rgb_camera_extr
    cameras["depth_camera_extr"] = depth_camera_extr
    return cameras
コード例 #8
0
from detector.hand_dataset.bbox_dataset import HandBBoxDataset as HandDataset
from detector.graphics import camera
from detector.hand_dataset.common_dataset import NUM_KEYPOINTS, STANDARD_KEYPOINT_NAMES, COLOR_MAP, EDGES, ROOT_IDX, REF_EDGE
from detector.hand_dataset.common_dataset import make_keypoint_converter, wrist2palm
from detector.hand_dataset.bbox_dataset import HandBBoxDataset as HandDataset
from detector.hand_dataset.geometry_utils import DATA_CONVENTION

# Puseudo image center and focal length
# This dataset provides only 2D image. to utilize our script that utilize 3D information,
# We will create puseudo 3D coordinate and camera matrix

U0 = V0 = 300
F = 500

RGB_CAMERA_INTR = camera.CameraIntr(fx=F, fy=F, u0=U0, v0=V0)
KEYPOINT_NAMES = STANDARD_KEYPOINT_NAMES


class HandDBBaseDataset(DatasetMixin):
    def __init__(self, dataset_dir, mode="train", debug=False):
        self.mode = mode
        self.rgb_camera = RGB_CAMERA_INTR
        self.depth_camera = None
        self.n_joints = NUM_KEYPOINTS
        self.root_idx = ROOT_IDX
        self.ref_edge = REF_EDGE
        self.annotations = self.load_annotations(dataset_dir, debug=debug)

    def __len__(self):
        return len(self.annotations)