Пример #1
0
def preprocess_3d_data(matched_data, camera_intrinsics ):
    camera_matrix = camera_intrinsics["camera_matrix"]
    dist_coefs = camera_intrinsics["dist_coefs"]

    ref_processed = []
    pupil0_processed = []
    pupil1_processed = []

    is_binocular = len(matched_data[0] ) == 3
    for data_point in matched_data:
        try:
            # taking the pupil normal as line of sight vector
            pupil0 = data_point['pupil']
            gaze_vector0 = np.array(pupil0['circle_3d']['normal'])
            pupil0_processed.append( gaze_vector0 )

            if is_binocular: # we have binocular data
                pupil1 = data_point['pupil1']
                gaze_vector1 = np.array(pupil1['circle_3d']['normal'])
                pupil1_processed.append( gaze_vector1 )

            # projected point uv to normal ray vector of camera
            ref = data_point['ref']
            ref_vector =  undistort_unproject_pts(ref['screen_pos'] , camera_matrix, dist_coefs).tolist()[0]
            ref_vector = ref_vector / np.linalg.norm(ref_vector)
            # assuming a fixed (assumed) distance we get a 3d point in world camera 3d coords.
            ref_processed.append( np.array(ref_vector) )

        except KeyError as e:
            # this pupil data point did not have 3d detected data.
            pass

    return ref_processed,pupil0_processed,pupil1_processed
Пример #2
0
def preprocess_3d_data_binocular(matched_data, camera_intrinsics , calibration_distance):

    camera_matrix = camera_intrinsics["camera_matrix"]
    dist_coefs = camera_intrinsics["dist_coefs"]

    cal_data = []
    for triplet in matched_data:
        ref,p0,p1 = triplet['ref'],triplet['pupil0'],triplet['pupil1']
        try:
            # taking the pupil normal as line of sight vector
            # we multiply by a fixed (assumed) distance and
            # add the sphere pos to get the 3d gaze point in eye camera 3d coords
            sphere_pos0 = np.array(p0['sphere']['center'])
            gaze_pt0 = np.array(p0['circle3D']['normal']) * calibration_distance + sphere_pos0


            sphere_pos1 = np.array(p1['sphere']['center'])
            gaze_pt1 = np.array(p1['circle3D']['normal']) * calibration_distance + sphere_pos1


            # projected point uv to normal ray vector of camera
            ref_vector =  undistort_unproject_pts(ref['screen_pos'] , camera_matrix, dist_coefs).tolist()[0]
            ref_vector = ref_vector / np.linalg.norm(ref_vector)
            # assuming a fixed (assumed) distance we get a 3d point in world camera 3d coords.
            ref_pt_3d = ref_vector*calibration_distance


            point_triple_3d = tuple(gaze_pt0), tuple(gaze_pt1) , ref_pt_3d
            cal_data.append(point_triple_3d)
        except KeyError as e:
            # this pupil data point did not have 3d detected data.
            pass

    return cal_data
Пример #3
0
def preprocess_3d_data_monocular(matched_data, camera_intrinsics,
                                 calibration_distance):
    camera_matrix = camera_intrinsics["camera_matrix"]
    dist_coefs = camera_intrinsics["dist_coefs"]

    cal_data = []
    for pair in matched_data:
        ref, pupil = pair['ref'], pair['pupil']
        try:
            # taking the pupil normal as line of sight vector
            # we multiply by a fixed (assumed) distace and
            # add the sphere pos to get the 3d gaze point in eye camera 3d coords
            sphere_pos = np.array(pupil['sphere']['center'])
            gaze_pt_3d = np.array(pupil['circle3D']['normal']
                                  ) * calibration_distance + sphere_pos

            # projected point uv to normal ray vector of camera
            ref_vector = undistort_unproject_pts(ref['screen_pos'],
                                                 camera_matrix,
                                                 dist_coefs).tolist()[0]
            ref_vector = ref_vector / np.linalg.norm(ref_vector)
            # assuming a fixed (assumed) distance we get a 3d point in world camera 3d coords.
            ref_pt_3d = ref_vector * calibration_distance

            point_pair_3d = tuple(gaze_pt_3d), ref_pt_3d
            cal_data.append(point_pair_3d)
        except KeyError as e:
            # this pupil data point did not have 3d detected data.
            pass

    return cal_data