Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/pupil-labs/pupil
Browse files Browse the repository at this point in the history
  • Loading branch information
mkassner committed Apr 25, 2018
2 parents a7a9f7d + 4c90f4f commit a3c6462
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 48 deletions.
5 changes: 3 additions & 2 deletions pupil_src/shared_modules/background_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ def _wrapper(self, pipe, _should_terminate_flag, generator, *args, **kwargs):
pipe.send(datum)
except Exception as e:
pipe.send(e)
import traceback
logger.warning(traceback.format_exc())
if not isinstance(e, EarlyCancellationError):
import traceback
print(traceback.format_exc())
else:
pipe.send(StopIteration())
finally:
Expand Down
51 changes: 16 additions & 35 deletions pupil_src/shared_modules/calibration_routines/calibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,53 +313,34 @@ def find_nearest_idx(array,value):


def preprocess_2d_data_monocular(matched_data):
cal_data = []
for pair in matched_data:
ref,pupil = pair['ref'],pair['pupil']
cal_data.append( (pupil["norm_pos"][0], pupil["norm_pos"][1],ref['norm_pos'][0],ref['norm_pos'][1]) )
cal_data = [(*pair['pupil']["norm_pos"],
*pair['ref']["norm_pos"])
for pair in matched_data]
return cal_data


def preprocess_2d_data_binocular(matched_data):
cal_data = []
for triplet in matched_data:
ref,p0,p1 = triplet['ref'],triplet['pupil'],triplet['pupil1']
data_pt = p0["norm_pos"][0], p0["norm_pos"][1],p1["norm_pos"][0], p1["norm_pos"][1],ref['norm_pos'][0],ref['norm_pos'][1]
cal_data.append( data_pt )
cal_data = [(*triplet['pupil']["norm_pos"],
*triplet['pupil1']["norm_pos"],
*triplet['ref']["norm_pos"])
for triplet in matched_data]
return cal_data

def preprocess_3d_data(matched_data, g_pool):
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 )
def preprocess_3d_data(matched_data, g_pool):
pupil0_processed = [dp['pupil']['circle_3d']['normal'] for dp in matched_data if 'circle_3d' in dp['pupil']]

# projected point uv to normal ray vector of camera
ref = data_point['ref']['screen_pos']
ref_vector = np.array(ref).reshape(-1,1,2)
ref_vector = g_pool.capture.intrinsics.unprojectPoints(ref_vector, normalize=True)
# assuming a fixed (assumed) distance we get a 3d point in world camera 3d coords.
ref_processed.append(ref_vector)
pupil1_processed = [dp['pupil1']['circle_3d']['normal'] for dp in matched_data if 'pupil1' in dp and 'circle_3d' in dp['pupil1']]

except KeyError as e:
# this pupil data point did not have 3d detected data.
pass
ref = np.array([dp['ref']['screen_pos'] for dp in matched_data])
ref_processed = g_pool.capture.intrinsics.unprojectPoints(ref, normalize=True)

return ref_processed,pupil0_processed,pupil1_processed
return ref_processed, pupil0_processed, pupil1_processed


def find_rigid_transform(A, B):
# we expect the shape to be of length 2
assert len(A.shape) == len(B.shape) == 2
assert A.shape[0] == B.shape[0]

centroid_A = np.mean(A, axis=0)
Expand Down
16 changes: 5 additions & 11 deletions pupil_src/shared_modules/camera_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,9 @@ def unprojectPoints(self, pts_2d, use_distortion=True, normalize=False):
Undistorts points according to the camera model.
cv2.fisheye.undistortPoints does *NOT* perform the same unprojection step the original cv2.unprojectPoints does.
Thus we implement this function ourselves.
:param pts_2d: Distorted points. Can be a list of points or a single point.
:return: Array of unprojected 3d points
:param pts_2d, shape: Nx2
:return: Array of unprojected 3d points, shape: Nx3
"""
input_shape = pts_2d.shape

pts_2d = pts_2d.reshape((-1, 2))
eps = np.finfo(np.float32).eps
Expand Down Expand Up @@ -303,15 +302,10 @@ def undistort(self, img):
def unprojectPoints(self, pts_2d, use_distortion=True, normalize=False):
"""
Undistorts points according to the camera model.
:param pts_2d: 2d points. Can be a list of points or a single point.
:return: Array of unprojected 3d points
:param pts_2d, shape: Nx2
:return: Array of unprojected 3d points, shape: Nx3
"""
pts_2d = np.array(pts_2d, dtype=np.float32)
input_shape = pts_2d.shape

# If given a single point expand to a 1-point list
if len(pts_2d.shape) == 1:
pts_2d = pts_2d.reshape((1, 2))

# Delete any posibly wrong 3rd dimension
if pts_2d.ndim == 3:
Expand All @@ -336,7 +330,7 @@ def unprojectPoints(self, pts_2d, use_distortion=True, normalize=False):
pts_3d.shape = -1, 3

if normalize:
pts_3d /= np.linalg.norm(pts_3d, axis=1)
pts_3d /= np.linalg.norm(pts_3d, axis=1)[:, np.newaxis]

return pts_3d

Expand Down

0 comments on commit a3c6462

Please sign in to comment.