def _convert_2d_to_3d_point_undistort(point_group, camera, fbw, fbh, lcox,
                                      lcoy, camera_fov, frame, pos, depth):
    """
    Convert a 2D point (undistorted) into a 3D point, in world space.

    :param point_group: Camera Point Group for camera.
    :param camera: The camera to use for rolling shutter calculations.
    :param fbw: Camera's film back width value.
    :param fbh: Camera's film back height value.
    :param lcox: Camera lens lens center offset X value.
    :param lcoy: Camera lens lens center offset Y value.
    :param camera_fov: Camera Field of View as list of left, right,
                       bottom and top.
    :param frame: The 2D point's frame number (in internal 3DE frame numbers).
    :param pos: Input 2D data.
    :param depth: The content distance to calculate rolling shutter at.

    :return: Corrected 2D point.
    :rtype: vec2d
    """
    focal = tde4.getCameraFocalLength(camera, frame)
    r3d = vl_sdv.mat3d(tde4.getPGroupRotation3D(point_group, camera, frame))
    p3d = vl_sdv.vec3d(tde4.getPGroupPosition3D(point_group, camera, frame))
    left, right, bottom, top = camera_fov

    p2d = [0, 0]
    p2d[0] = (pos[0] - left) / (right - left)
    p2d[1] = (pos[1] - bottom) / (top - bottom)
    p2d = tde4.removeDistortion2D(camera, frame, p2d)

    p2d_cm = vl_sdv.vec2d((p2d[0] - 0.5) * fbw - lcox,
                          (p2d[1] - 0.5) * fbh - lcoy)
    homogeneous_point = r3d * vl_sdv.vec3d(p2d_cm[0], p2d_cm[1], -focal).unit()
    out_point = homogeneous_point * depth + p3d
    return out_point
Exemple #2
0
def _set_camera_rotation(pgroup_id, cam_id, rx_samples, ry_samples, rz_samples,
                         file_start_frame, file_end_frame, chosen_start_frame,
                         chosen_end_frame):
    """
    Set the camera rotation values on the given 3DE camera ids.

    :param pgroup_id: The Point Group ID with the active camera in it.
    :type pgroup_id: str

    :param cam_id: The Camera ID to apply data to.
    :type cam_id: str

    :param rx_samples: Frame/value pairs for Rotate X, representing
                       a curve of values.
    :type rx_samples: [(int, float), ..]

    :param ry_samples: Frame/value pairs for Rotate Y, representing
                       a curve of values.
    :type ry_samples: [(int, float), ..]

    :param rz_samples: Frame/value pairs for Rotate Z, representing
                       a curve of values.
    :type rz_samples: [(int, float), ..]

    :param file_start_frame: The start frame available from the parsed file.
    :type file_start_frame: int

    :param file_end_frame: The end frame available from the parsed file.
    :type file_end_frame: int

    :param chosen_start_frame: The start frame that the user wants to limit to.
    :type chosen_start_frame: int

    :param chosen_end_frame: The end frame that the user wants to limit to.
    :type chosen_end_frame: int

    :returns: Were the rotation values changed?
    :rtype: bool
    """
    values_were_set = False
    assert isinstance(file_start_frame, (int, long))
    assert isinstance(file_end_frame, (int, long))
    assert isinstance(chosen_start_frame, (int, long))
    assert isinstance(chosen_end_frame, (int, long))
    assert rx_samples
    assert ry_samples
    assert rz_samples

    samples_list = (rx_samples, ry_samples, rz_samples)
    frames = _get_frame_list_to_set_values(cam_id, samples_list,
                                           file_start_frame, file_end_frame,
                                           chosen_start_frame,
                                           chosen_end_frame)

    rotate_data = dict()
    for component_index, samples in [(0, rx_samples), (1, ry_samples),
                                     (2, rz_samples)]:
        for frame, value in samples:
            frame = int(frame)
            if frame not in rotate_data:
                rotate_data[frame] = [None, None, None]
            rotate_data[frame][component_index] = (value * PI) / 180.0

    for global_frame in frames:
        rot_value = rotate_data.get(global_frame)
        if rot_value is None:
            continue
        rot_x, rot_y, rot_z = rot_value
        r3d = vl_sdv.rot3d(rot_x, rot_y, rot_z, vl_sdv.VL_APPLY_ZXY)
        r3d = vl_sdv.mat3d(r3d)
        r3d0 = [[r3d[0][0], r3d[0][1], r3d[0][2]],
                [r3d[1][0], r3d[1][1], r3d[1][2]],
                [r3d[2][0], r3d[2][1], r3d[2][2]]]
        # Internally, 3DE always starts at frame 1.
        raw_frame = 1 + (global_frame - file_start_frame)
        tde4.setPGroupRotation3D(pgroup_id, cam_id, raw_frame, r3d0)
        values_were_set = True
    return values_were_set
Exemple #3
0
def convertToAngles(r3d):
    rot = vl_sdv.rot3d(vl_sdv.mat3d(r3d)).angles(vl_sdv.VL_APPLY_ZXY)
    rx = (rot[0] * 180.0) / 3.141592654
    ry = (rot[1] * 180.0) / 3.141592654
    rz = (rot[2] * 180.0) / 3.141592654
    return (rx, ry, rz)
Exemple #4
0
def _remove_rs_from_2d_point(point_group, camera, frame, input_2d, depth):
    """
    Correct Rolling Shutter for the given input_2d point data, on frame.

    :param point_group: Camera Point Group for camera.
    :param camera: The camera to use for rolling shutter calculations.
    :param frame: The 2D point's frame number (in internal 3DE frame numbers).
    :param input_2d: Input 2D data.
    :param depth: The content distance to calculate rolling shutter at.

    :return: 2D point with corrected position.
    :rtype: [float, float]
    """
    assert isinstance(input_2d, vl_sdv.vec2d)
    num_frames = tde4.getCameraNoFrames(camera)
    if num_frames == 1:
        return input_2d

    # Static camera and lens values.
    camera_fps = tde4.getCameraFPS(camera)
    camera_fov = tde4.getCameraFOV(camera)
    lens = tde4.getCameraLens(camera)
    fbw = tde4.getLensFBackWidth(lens)
    fbh = tde4.getLensFBackHeight(lens)
    lcox = tde4.getLensLensCenterX(lens)
    lcoy = tde4.getLensLensCenterY(lens)
    rs_time_shift = tde4.getCameraRollingShutterTimeShift(camera)
    rs_value = rs_time_shift * camera_fps

    # Sample at previous frame
    prev_pos = vl_sdv.vec3d(0, 0, 0)
    prev_frame = frame - 1
    if frame > 1:
        prev_pos = _convert_2d_to_3d_point_undistort(
            point_group, camera,
            fbw, fbh, lcox, lcoy,
            camera_fov,
            prev_frame, input_2d, depth)

    # Sample at next frame
    next_pos = vl_sdv.vec3d(0, 0, 0)
    next_frame = frame + 1
    if frame < num_frames:
        next_pos = _convert_2d_to_3d_point_undistort(
            point_group, camera,
            fbw, fbh, lcox, lcoy,
            camera_fov,
            next_frame, input_2d, depth)

    # Sample at current frame
    curr_pos = _convert_2d_to_3d_point_undistort(
        point_group, camera,
        fbw, fbh, lcox, lcoy,
        camera_fov,
        frame, input_2d, depth)

    # Blend previous, next and current frame values based on the
    # position of the 2D point vertical position and the rolling
    # shutter value.
    if frame == 1:
        prev_pos = curr_pos + (curr_pos - next_pos)
    if frame == num_frames:
        next_pos = curr_pos + (curr_pos - prev_pos)
    t = rs_value * (1.0 - input_2d[1])
    curr_pos = _apply_rs_correction(-t, prev_pos, curr_pos, next_pos)

    # Back-projection
    focal = tde4.getCameraFocalLength(camera, frame)
    r3d = vl_sdv.mat3d(tde4.getPGroupRotation3D(point_group, camera, frame))
    p3d = vl_sdv.vec3d(tde4.getPGroupPosition3D(point_group, camera, frame))
    d = r3d.trans() * (curr_pos - p3d)
    p2d = [0, 0]
    p2d[0] = (d[0] * focal / (-d[2] * fbw)) + (lcox / fbw) + 0.5
    p2d[1] = (d[1] * focal / (-d[2] * fbh)) + (lcoy / fbh) + 0.5
    p = tde4.applyDistortion2D(camera, frame, p2d)
    left, right, bottom, top = camera_fov
    p = vl_sdv.vec2d((p[0] * (right - left)) + left,
                     (p[1] * (top - bottom)) + bottom)
    v = (input_2d + (input_2d - p)).list()
    return v