コード例 #1
0
def transform_world_to_camera(poses_set, cams, ncams=4 ):
    """
    Project 3d poses from world coordinate to camera coordinate system
    Args
      poses_set: dictionary with 3d poses
      cams: dictionary with cameras
      ncams: number of cameras per subject
    Return:
      t3d_camera: dictionary with 3d poses in camera coordinate
    """
    t3d_camera = {}
    for t3dk in sorted( poses_set.keys() ):

      subj, action, seqname = t3dk
      t3d_world = poses_set[ t3dk ]

      for c in range( ncams ):
        R, T, f, c, k, p, name = cams[ (subj, c+1) ]
        camera_coord = cameras.world_to_camera_frame( np.reshape(t3d_world, [-1, 3]), R, T)
        camera_coord = np.reshape( camera_coord, [-1, len(H36M_NAMES)*3] )

        sname = seqname[:-3]+"."+name+".h5" # e.g.: Waiting 1.58860488.h5
        t3d_camera[ (subj, action, sname) ] = camera_coord

    return t3d_camera
コード例 #2
0
def transform_world_to_camera(poses_set, cams, ncams=4):
    """
    Project 3d poses from world coordinate to camera coordinate system
    Args
      poses_set: dictionary with 3d poses
      cams: dictionary with cameras
      ncams: number of cameras per subject
    Return:
      t3d_camera: dictionary with 3d poses in camera coordinate
    """
    t3d_camera = {}
    for t3dk in sorted(
            poses_set.keys()):  #获取已排序的列表副本,本例中即为键按照某种顺序排序后的列表:好像是字母顺序排列的

        subj, action, seqname = t3dk
        t3d_world = poses_set[t3dk]
        #print("t3d_world的维度大小为",t3d_world.shape) #(n,96)

        for c in range(ncams):
            R, T, f, c, k, p, name = cams[(subj, c + 1)]
            camera_coord = cameras.world_to_camera_frame(
                np.reshape(t3d_world, [-1, 3]), R, T)  #np.reshape()将其变为(m,3)
            #print("原camera_coord的大小",camera_coord.shape)
            camera_coord = np.reshape(
                camera_coord,
                [-1, len(H36M_NAMES) * 3])  #(n,96) 96是因为h3.6m一共有32个点,32*3=96
            #print("reshape后camera_coord的大小",camera_coord.shape)

            sname = seqname[:-3] + "." + name + ".h5"  # e.g.: Waiting 1.58860488.h5  即在.和h5之间加上摄像机的id
            #print("action和sname是",action,sname)
            t3d_camera[(subj, action, sname)] = camera_coord
    return t3d_camera
コード例 #3
0
def transform_world_to_camera(poses_set, cams, ncams=4):
    """
    Project 3d poses from world coordinate to camera coordinate system
    Args:
      poses_set: dictionary with 3d poses
      cams: dictionary with cameras
      ncams: number of cameras per subject
    Return:
      t3d_camera: dictionary with 3d poses in camera coordinate
    """
    t3d_camera = {}
    for t3dk in sorted(poses_set.keys()):
        subj, a, seqname = t3dk
        t3d_world = poses_set[t3dk]
        #print("#### SHAPE OF t3d_world::",t3d_world.shape)
        # FIXME this only works for real cameras
        for c in range(ncams):
            R, T, f, c, k, p, name = cams[(subj, c + 1)]
            camera_coord = cameras.world_to_camera_frame(
                np.reshape(t3d_world, [-1, 3]), R, T, f, c, k, p)
            camera_coord = np.reshape(camera_coord, [-1, 96])
            #print("#### SHAPE OF CAMCOORD::",camera_coord.shape)
            sname = seqname[:-3] + "." + name + ".h5"  #Waiting 1.58860488.h5
            t3d_camera[(subj, a, sname)] = camera_coord

    return t3d_camera
コード例 #4
0
ファイル: data_utils.py プロジェクト: neherh/3d-pose-baseline
def transform_world_to_camera(poses_set, cams, ncams=4 ):
    """
    Project 3d poses from world coordinate to camera coordinate system
    Args
      poses_set: dictionary with 3d poses
      cams: dictionary with cameras
      ncams: number of cameras per subject
    Return:
      t3d_camera: dictionary with 3d poses in camera coordinate
    """
    t3d_camera = {}
    for t3dk in sorted( poses_set.keys() ):

      subj, action, seqname = t3dk
      t3d_world = poses_set[ t3dk ]

      for c in range( ncams ):
        R, T, f, c, k, p, name = cams[ (subj, c+1) ]
        camera_coord = cameras.world_to_camera_frame( np.reshape(t3d_world, [-1, 3]), R, T)
        camera_coord = np.reshape( camera_coord, [-1, len(H36M_NAMES)*3] )

        sname = seqname[:-3]+"."+name+".h5" # e.g.: Waiting 1.58860488.h5
        t3d_camera[ (subj, action, sname) ] = camera_coord

    return t3d_camera
コード例 #5
0
def transform_world_to_camera(poses_set, cams, ncams=4, experimental=True):
    """
    Project 3d poses from world coordinate to camera coordinate system
    Args
      poses_set: dictionary with 3d poses
      cams: dictionary with cameras
      ncams: number of cameras per subject
    Return:
      t3d_camera: dictionary with 3d poses in camera coordinate
    """
    t3d_camera = {}
    for t3dk in sorted(poses_set.keys()):

        subj, action, seqname = t3dk
        t3d_world = poses_set[t3dk]

        for c in range(ncams):
            R, T, f, c, k, p, name = cams[(subj, c + 1)]
            if experimental:
                # Checks if a matrix is a valid rotation matrix.
                def isRotationMatrix(R):
                    Rt = np.transpose(R)
                    shouldBeIdentity = np.dot(Rt, R)
                    I = np.identity(3, dtype=R.dtype)
                    n = np.linalg.norm(I - shouldBeIdentity)
                    return n < 1e-6

                # Calculates rotation matrix to euler angles
                # The result is the same as MATLAB except the order
                # of the euler angles ( x and z are swapped ).
                def rotationMatrixToEulerAngles(R):
                    assert (isRotationMatrix(R))
                    sy = math.sqrt(R[0, 0] * R[0, 0] + R[1, 0] * R[1, 0])
                    singular = sy < 1e-6
                    if not singular:
                        x = math.atan2(R[2, 1], R[2, 2])
                        y = math.atan2(-R[2, 0], sy)
                        z = math.atan2(R[1, 0], R[0, 0])
                    else:
                        x = math.atan2(-R[1, 2], R[1, 1])
                        y = math.atan2(-R[2, 0], sy)
                        z = 0
                    return np.array([x, y, z])

                # Calculates Rotation Matrix given euler angles.
                def eulerAnglesToRotationMatrix(theta):
                    R_x = np.array(
                        [[1, 0, 0],
                         [0, math.cos(theta[0]), -math.sin(theta[0])],
                         [0, math.sin(theta[0]),
                          math.cos(theta[0])]])
                    R_y = np.array(
                        [[math.cos(theta[1]), 0,
                          math.sin(theta[1])], [0, 1, 0],
                         [-math.sin(theta[1]), 0,
                          math.cos(theta[1])]])
                    R_z = np.array(
                        [[math.cos(theta[2]), -math.sin(theta[2]), 0],
                         [math.sin(theta[2]),
                          math.cos(theta[2]), 0], [0, 0, 1]])
                    R = np.dot(R_z, np.dot(R_y, R_x))
                    return R

                ## x rotation
                # R[0][0] = 1
                # R[0][1] = 0
                # R[0][2] = 0
                # R[1][0] = 0
                # R[2][0] = 0
                ## y rotation
                # R[0][1] = 0
                # R[1][0] = 0
                # R[1][1] = 1
                # R[1][2] = 0
                # R[2][1] = 0
                ## z rotation
                # R[0][2] = 0
                # R[1][2] = 0
                # R[2][0] = 0
                # R[2][1] = 0
                # R[2][2] = 1
                ## Do the theta thing with euler angles
                theta = rotationMatrixToEulerAngles(R)
                theta[0] = 0
                theta[1] = 0
                R = eulerAnglesToRotationMatrix(theta)
            camera_coord = cameras.world_to_camera_frame(
                np.reshape(t3d_world, [-1, 3]), R, T)
            camera_coord = np.reshape(camera_coord, [-1, len(H36M_NAMES) * 3])

            sname = seqname[:-3] + "." + name + ".h5"  # e.g.: Waiting 1.58860488.h5
            t3d_camera[(subj, action, sname)] = camera_coord

    return t3d_camera