In [2]:
%matplotlib inline

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import cv2

In [199]:
# Come back to opencv
dims = (4,11)
im_size = (640,480)
num_pts = dims[0] * dims[1]

# initialize camera parameters
intrinsics1 = np.zeros( (3,3) )
intrinsics2 = np.zeros( (3,3) )
distortion1 = np.zeros( (8,1) )
distortion2 = np.zeros( (8,1) )

# Set initial guess for intrinsic camera parameters (focal length = 0.35cm)
intrinsics1[0,0] = 583.3 
intrinsics1[1,1] = 583.3 
intrinsics1[0,2] = 320
intrinsics1[1,2] = 240
intrinsics1[2,2] = 1.0

intrinsics2[0,0] = 583.3 
intrinsics2[1,1] = 583.3 
intrinsics2[0,2] = 320
intrinsics2[1,2] = 240
intrinsics2[2,2] = 1.0

img1 = cv2.imread("/Users/bwsprague/GradSchool/Research/BerkeleyVisionStats/data/raw/stereocalibration/kre/kre_cafe/calibration_frames_2012-08-01/cam1_frame_10.bmp",0)
img2 = cv2.imread("/Users/bwsprague/GradSchool/Research/BerkeleyVisionStats/data/raw/stereocalibration/kre/kre_cafe/calibration_frames_2012-08-01/cam2_frame_10.bmp",0)

[found1,points1] = cv2.findCirclesGridDefault(img1,dims,flags=(cv2.CALIB_CB_ASYMMETRIC_GRID))
[found2,points2] = cv2.findCirclesGridDefault(img2,dims,flags=(cv2.CALIB_CB_ASYMMETRIC_GRID))

In [213]:
def object_points(dims,num_images,square_size):
    '''determine 3d object points for each image
    '''

    width = dims[0]
    height = dims[1]
    num_pts = width*height

    opts = []
    for n in range(num_images):
        temp = np.zeros( (num_pts,3) )
        for i in range(height):
            for j in range(width):
                    if i%2==0:
                        temp[i*width+j,0] = (i*(square_size/2.00))
                        temp[i*width+j,1] = j*square_size
                        temp[i*width+j,2] = 0
                    else:
                        temp[i*width+j,0] = (i*(square_size/2.00))
                        temp[i*width+j,1] = (j*square_size) + square_size/2.00
                        temp[i*width+j,2] = 0
        opts.append(temp)
    opts = np.array(opts, dtype = np.float32)

    return opts

In [214]:
drawn_boards_1 = img1.copy()
drawn_boards_2 = img2.copy()
cv2.drawChessboardCorners(drawn_boards_1, dims, points1, found1)
cv2.drawChessboardCorners(drawn_boards_2, dims, points2, found2)

In [215]:
plt.imshow(drawn_boards_1, cmap='gray')


Out[215]:
<matplotlib.image.AxesImage at 0x14c42ed10>

In [216]:
opts = object_points(dims, 1, 4.35)
iptsF1 = [] #image point arrays to fill up
iptsF2 = []
temp1 = np.zeros( (num_pts,2) )
temp2 = np.zeros( (num_pts,2) )
if found1 and found2:
    for i in range(num_pts):
        temp1[i,0]=points1[i,0,0]
        temp1[i,1]=points1[i,0,1]
        temp2[i,0]=points2[i,0,0]
        temp2[i,1]=points2[i,0,1]

    iptsF1.append(temp1)
    iptsF2.append(temp2)
    
# convert image points to numpy
iptsF1 = np.array(iptsF1, dtype = np.float32)
iptsF2 = np.array(iptsF2, dtype = np.float32)

In [217]:
opts


Out[217]:
array([[[  0.        ,   0.        ,   0.        ],
        [  0.        ,   4.3499999 ,   0.        ],
        [  0.        ,   8.69999981,   0.        ],
        [  0.        ,  13.05000019,   0.        ],
        [  2.17499995,   2.17499995,   0.        ],
        [  2.17499995,   6.5250001 ,   0.        ],
        [  2.17499995,  10.875     ,   0.        ],
        [  2.17499995,  15.22500038,   0.        ],
        [  4.3499999 ,   0.        ,   0.        ],
        [  4.3499999 ,   4.3499999 ,   0.        ],
        [  4.3499999 ,   8.69999981,   0.        ],
        [  4.3499999 ,  13.05000019,   0.        ],
        [  6.5250001 ,   2.17499995,   0.        ],
        [  6.5250001 ,   6.5250001 ,   0.        ],
        [  6.5250001 ,  10.875     ,   0.        ],
        [  6.5250001 ,  15.22500038,   0.        ],
        [  8.69999981,   0.        ,   0.        ],
        [  8.69999981,   4.3499999 ,   0.        ],
        [  8.69999981,   8.69999981,   0.        ],
        [  8.69999981,  13.05000019,   0.        ],
        [ 10.875     ,   2.17499995,   0.        ],
        [ 10.875     ,   6.5250001 ,   0.        ],
        [ 10.875     ,  10.875     ,   0.        ],
        [ 10.875     ,  15.22500038,   0.        ],
        [ 13.05000019,   0.        ,   0.        ],
        [ 13.05000019,   4.3499999 ,   0.        ],
        [ 13.05000019,   8.69999981,   0.        ],
        [ 13.05000019,  13.05000019,   0.        ],
        [ 15.22500038,   2.17499995,   0.        ],
        [ 15.22500038,   6.5250001 ,   0.        ],
        [ 15.22500038,  10.875     ,   0.        ],
        [ 15.22500038,  15.22500038,   0.        ],
        [ 17.39999962,   0.        ,   0.        ],
        [ 17.39999962,   4.3499999 ,   0.        ],
        [ 17.39999962,   8.69999981,   0.        ],
        [ 17.39999962,  13.05000019,   0.        ],
        [ 19.57500076,   2.17499995,   0.        ],
        [ 19.57500076,   6.5250001 ,   0.        ],
        [ 19.57500076,  10.875     ,   0.        ],
        [ 19.57500076,  15.22500038,   0.        ],
        [ 21.75      ,   0.        ,   0.        ],
        [ 21.75      ,   4.3499999 ,   0.        ],
        [ 21.75      ,   8.69999981,   0.        ],
        [ 21.75      ,  13.05000019,   0.        ]]], dtype=float32)

In [218]:
iptsF1


Out[218]:
array([[[ 207.78390503,   66.03547668],
        [ 256.71310425,   65.93625641],
        [ 305.38067627,   66.60367584],
        [ 353.73757935,   68.18579102],
        [ 231.65316772,   85.31785583],
        [ 281.59561157,   85.83804321],
        [ 331.33093262,   86.69407654],
        [ 380.23162842,   88.36862183],
        [ 205.06176758,  105.67311859],
        [ 256.63638306,  105.81443024],
        [ 307.71914673,  106.49111938],
        [ 358.18441772,  107.63070679],
        [ 230.15908813,  126.88961792],
        [ 282.84799194,  127.58821869],
        [ 334.7467041 ,  128.2159729 ],
        [ 385.52572632,  129.22779846],
        [ 203.39749146,  150.13171387],
        [ 256.57455444,  149.47001648],
        [ 310.06137085,  150.08459473],
        [ 362.67480469,  150.90522766],
        [ 229.58032227,  173.42391968],
        [ 284.10314941,  173.12120056],
        [ 338.35327148,  173.77749634],
        [ 391.06442261,  174.19758606],
        [ 201.29463196,  198.27680969],
        [ 257.10186768,  197.94418335],
        [ 312.66976929,  197.48748779],
        [ 367.35134888,  198.11096191],
        [ 229.02749634,  223.83743286],
        [ 285.84085083,  223.49871826],
        [ 342.05532837,  223.0255127 ],
        [ 396.79101562,  223.22277832],
        [ 200.10620117,  250.52828979],
        [ 257.90979004,  250.30583191],
        [ 315.63812256,  249.67027283],
        [ 372.21624756,  249.0398407 ],
        [ 228.7938385 ,  277.93719482],
        [ 287.71765137,  277.59689331],
        [ 345.95809937,  276.47003174],
        [ 402.34634399,  275.6880188 ],
        [ 199.25540161,  306.50878906],
        [ 258.91934204,  305.99584961],
        [ 318.54632568,  305.23638916],
        [ 376.84130859,  303.66815186]]], dtype=float32)

In [219]:
(cam1rms, intrinsics1, distortion1, rotv1, trav1) = cv2.calibrateCamera(opts, iptsF1, im_size, intrinsics1, distortion1,
                                                        flags=int(cv2.CALIB_USE_INTRINSIC_GUESS | cv2.CALIB_RATIONAL_MODEL))

In [220]:
intrinsics1


Out[220]:
array([[ 618.1277984 ,    0.        ,  315.31625279],
       [   0.        ,  617.3119656 ,  234.92422865],
       [   0.        ,    0.        ,    1.        ]])

In [221]:
retval, rvec, tvec = cv2.solvePnP(opts, iptsF1, intrinsics1, distortion1)

In [222]:
board_points = np.array([[0., 0, 0],
                         [5,0,0],
                         [0,5,0],
                         [0,0,5]])

In [223]:
outpts, jac = cv2.projectPoints(board_points, rvec, tvec, intrinsics1, distortion1)

In [224]:
outpts


Out[224]:
array([[[ 207.48996504,   66.03105775]],

       [[ 204.85811282,  112.23177385]],

       [[ 263.94306869,   65.98013859]],

       [[ 205.70519305,   29.49753781]]])

In [225]:
tmp_im = cv2.cvtColor(img1.copy(), cv2.COLOR_GRAY2RGB)
cv2.circle(tmp_im, tuple(outpts[0].squeeze().astype('int')), 8, (255,255,255), 3)
cv2.circle(tmp_im, tuple(outpts[1].squeeze().astype('int')), 8, (255,0,0), 3)
cv2.circle(tmp_im, tuple(outpts[2].squeeze().astype('int')), 8, (0,255,0), 3)
cv2.circle(tmp_im, tuple(outpts[3].squeeze().astype('int')), 8, (0,0,255), 3)
plt.imshow(tmp_im)


Out[225]:
<matplotlib.image.AxesImage at 0x14c84b650>

In [61]:
(stereorms, intrinsics1, distortion1, intrinsics2, distortion2, R, T, E, F) = cv2.stereoCalibrate(opts, iptsF1, iptsF2, im_size,
                                                            intrinsics1, distortion1, intrinsics2, distortion2,
                                                            criteria=(cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 300, 1e-7),
                                                            flags=(cv2.CALIB_USE_INTRINSIC_GUESS | cv2.CALIB_RATIONAL_MODEL))

In [55]:
intrinsics1


Out[55]:
array([[ 612.79173557,    0.        ,  317.02886355],
       [   0.        ,  611.99115861,  231.99856769],
       [   0.        ,    0.        ,    1.        ]])

In [83]:
intrinsics1


Out[83]:
array([[ 611.99090947,    0.        ,  319.08558099],
       [   0.        ,  614.71060312,  240.316939  ],
       [   0.        ,    0.        ,    1.        ]])

In [64]:
T


Out[64]:
array([[-6.22533441],
       [ 0.04330649],
       [-2.71939064]])

In [98]:
cv2.projectPoints(np.array([[0,100,-100.0]]), cv2.Rodrigues(np.array([[1., 0,0],[0,1,0],[0,0,1]]))[0], np.zeros((3,1)), intrinsics1, np.zeros((1,4)))[0]


Out[98]:
array([[[ 319.08558099, -374.39366412]]])

In [99]:
opts


Out[99]:
array([[[  0.        ,   0.        ,   0.        ],
        [  0.        ,   4.3499999 ,   0.        ],
        [  0.        ,   8.69999981,   0.        ],
        [  0.        ,  13.05000019,   0.        ],
        [  2.17499995,   2.17499995,   0.        ],
        [  2.17499995,   6.5250001 ,   0.        ],
        [  2.17499995,  10.875     ,   0.        ],
        [  2.17499995,  15.22500038,   0.        ],
        [  4.3499999 ,   0.        ,   0.        ],
        [  4.3499999 ,   4.3499999 ,   0.        ],
        [  4.3499999 ,   8.69999981,   0.        ],
        [  4.3499999 ,  13.05000019,   0.        ],
        [  6.5250001 ,   2.17499995,   0.        ],
        [  6.5250001 ,   6.5250001 ,   0.        ],
        [  6.5250001 ,  10.875     ,   0.        ],
        [  6.5250001 ,  15.22500038,   0.        ],
        [  8.69999981,   0.        ,   0.        ],
        [  8.69999981,   4.3499999 ,   0.        ],
        [  8.69999981,   8.69999981,   0.        ],
        [  8.69999981,  13.05000019,   0.        ],
        [ 10.875     ,   2.17499995,   0.        ],
        [ 10.875     ,   6.5250001 ,   0.        ],
        [ 10.875     ,  10.875     ,   0.        ],
        [ 10.875     ,  15.22500038,   0.        ],
        [ 13.05000019,   0.        ,   0.        ],
        [ 13.05000019,   4.3499999 ,   0.        ],
        [ 13.05000019,   8.69999981,   0.        ],
        [ 13.05000019,  13.05000019,   0.        ],
        [ 15.22500038,   2.17499995,   0.        ],
        [ 15.22500038,   6.5250001 ,   0.        ],
        [ 15.22500038,  10.875     ,   0.        ],
        [ 15.22500038,  15.22500038,   0.        ],
        [ 17.39999962,   0.        ,   0.        ],
        [ 17.39999962,   4.3499999 ,   0.        ],
        [ 17.39999962,   8.69999981,   0.        ],
        [ 17.39999962,  13.05000019,   0.        ],
        [ 19.57500076,   2.17499995,   0.        ],
        [ 19.57500076,   6.5250001 ,   0.        ],
        [ 19.57500076,  10.875     ,   0.        ],
        [ 19.57500076,  15.22500038,   0.        ],
        [ 21.75      ,   0.        ,   0.        ],
        [ 21.75      ,   4.3499999 ,   0.        ],
        [ 21.75      ,   8.69999981,   0.        ],
        [ 21.75      ,  13.05000019,   0.        ]]], dtype=float32)

Testing frame syncing


In [7]:
frames = pd.read_hdf("/Users/bwsprague/GradSchool/Research/BerkeleyVisionStats/testing/parser_output/frame_output.h5", 'frames')
task_data = pd.read_hdf("/Users/bwsprague/GradSchool/Research/BerkeleyVisionStats/testing/parser_output/task_output.h5", 'task')
rt_data = pd.read_hdf("/Users/bwsprague/GradSchool/Research/BerkeleyVisionStats/testing/parser_output/rt_output.h5", 'rt')

In [195]:
task_data['both', 'frame_time'] = np.nan
task_data['both', 'frame_count'] = np.nan
task_data['both', 'frame_time_diff'] = np.nan

In [3]:
earliest_time = task_data.index.levels[1].min()
latest_time = task_data.index.levels[1].max()

In [4]:
task_frames = frames[(frames['time']>earliest_time) & (frames['time']<latest_time)]

In [198]:
task_frames.shape


Out[198]:
(34057, 2)

In [5]:
count = 0

for i, frame in task_frames.iterrows():
      
    time_diffs = task_data.index.levels[1] - frame['time']
    time_diffs = time_diffs.to_series().reset_index(drop=True)
    time_diffs.index = task_data.index
    time_range_mask = np.abs(time_diffs) < 15
    data_of_interest = task_data.loc[time_range_mask]
    good_data = data_of_interest[data_of_interest['both', 'quality'] == 'GOOD']
    indices_of_interest = data_of_interest.index
    task_data.loc[indices_of_interest, ('both', 'frame_time_diff')] = time_diffs
    
    indices_of_interest = good_data.index
    if not time_diffs[indices_of_interest].empty:
        smallest_time_diff_loc = np.abs(time_diffs.loc[indices_of_interest]).argmin()
        task_data.loc[smallest_time_diff_loc, ('both', 'frame_time')] = frame['time']
        task_data.loc[smallest_time_diff_loc, ('both', 'frame_count')] = frame['press num']
    
    count += 1
    if count > 100:
        break
        
print frame


time         1656983
press num       3471
Name: 3471, dtype: int64

In [7]:
task_data.iloc[130:200]


Out[7]:
left right left right both
href x href y pupil area href x href y pupil area flag flag quality frame_time_diff frame_time frame_count
rep time
1 1653580 -1904 -420 1810 -917 -171 1329 FIX FIX GOOD NaN NaN NaN
1653584 -1903 -412 1814 -913 -156 1337 FIX FIX GOOD NaN NaN NaN
1653588 -1905 -389 1818 -915 -142 1339 FIX FIX GOOD NaN NaN NaN
1653592 -1903 -388 1825 -916 -137 1342 FIX FIX GOOD NaN NaN NaN
1653596 -1902 -386 1832 -924 -135 1354 FIX FIX GOOD NaN NaN NaN
1653600 -1904 -368 1836 -925 -118 1354 FIX FIX GOOD NaN NaN NaN
1653604 -1905 -359 1836 -925 -101 1354 FIX FIX GOOD NaN NaN NaN
1653608 -1905 -349 1836 -928 -94 1354 FIX FIX GOOD NaN NaN NaN
1653612 -1915 -323 1842 -932 -87 1356 FIX FIX GOOD NaN NaN NaN
1653616 -1918 -318 1844 -936 -68 1359 FIX FIX GOOD NaN NaN NaN
1653620 -1919 -313 1849 -940 -60 1365 FIX FIX GOOD NaN NaN NaN
1653624 -1919 -309 1853 -934 -50 1368 FIX FIX GOOD NaN NaN NaN
1653628 -1921 -284 1857 -937 -50 1371 FIX FIX GOOD NaN NaN NaN
1653632 -1923 -281 1860 -940 -50 1379 FIX FIX GOOD NaN NaN NaN
1653636 -1922 -279 1868 -951 -39 1381 FIX FIX GOOD NaN NaN NaN
1653640 -1925 -274 1877 -956 -35 1384 FIX FIX GOOD NaN NaN NaN
1653644 -1928 -272 1877 -960 -20 1384 FIX FIX GOOD NaN NaN NaN
1653648 -1931 -270 1881 -964 -20 1385 FIX FIX GOOD NaN NaN NaN
1653652 -1934 -268 1885 -967 -21 1388 FIX FIX GOOD NaN NaN NaN
1653656 -1934 -267 1890 -986 -25 1391 FIX FIX GOOD -11 NaN NaN
1653660 -1934 -246 1895 -990 -22 1393 FIX FIX GOOD -7 NaN NaN
1653664 -1951 -241 1900 -993 -19 1398 FIX FIX GOOD -3 NaN NaN
1653668 -1958 -227 1909 -995 8 1403 FIX FIX GOOD 1 1653667 3371
1653672 -1965 -213 1909 -1000 14 1412 FIX FIX GOOD -11 NaN NaN
1653676 -1966 -206 1910 -1005 19 1413 FIX FIX GOOD -7 NaN NaN
1653680 -1972 -203 1915 -1009 41 1414 FIX FIX GOOD -3 NaN NaN
1653684 -1973 -200 1920 -1013 62 1416 FIX FIX GOOD 1 1653683 3372
1653688 -1981 -186 1928 -1013 64 1418 FIX FIX GOOD 5 NaN NaN
1653692 -1988 -183 1928 -1017 64 1421 FIX FIX GOOD 9 NaN NaN
1653696 -1995 -180 1934 -1021 95 1430 FIX FIX GOOD 13 NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ...
1653740 -2066 -65 1956 -1091 196 1441 FIX FIX GOOD -9 NaN NaN
1653744 -2070 -22 1961 -1100 223 1442 FIX FIX GOOD -5 NaN NaN
1653748 -2075 -15 1969 -1112 250 1442 FIX FIX GOOD -1 1653749 3374
1653752 -2080 -7 1969 -1122 256 1442 FIX FIX GOOD 3 NaN NaN
1653756 -2087 10 1968 -1125 253 1442 FIX FIX GOOD 7 NaN NaN
1653760 -2114 28 1967 -1129 260 1442 FIX FIX GOOD 11 NaN NaN
1653764 -2123 60 1967 -1129 267 1444 FIX FIX GOOD NaN NaN NaN
1653768 -2131 77 1967 -1144 263 1449 FIX FIX GOOD NaN NaN NaN
1653772 -2135 81 1969 -1158 264 1449 FIX FIX GOOD -11 NaN NaN
1653776 -2152 86 1970 -1162 266 1449 FIX FIX GOOD -7 NaN NaN
1653780 -2168 91 1970 -1165 265 1449 FIX FIX GOOD -3 NaN NaN
1653784 -2184 108 1977 -1171 264 1449 FIX FIX GOOD 1 1653783 3375
1653788 -2189 113 1981 -1171 288 1453 FIX FIX GOOD 5 NaN NaN
1653792 -2195 119 1983 -1171 293 1458 FIX FIX GOOD 9 NaN NaN
1653796 -2196 129 1984 -1190 293 1462 FIX FIX GOOD 13 NaN NaN
1653800 -2203 139 1985 -1210 313 1462 FIX FIX GOOD NaN NaN NaN
1653804 -2232 141 1987 -1219 325 1462 FIX FIX GOOD -12 NaN NaN
1653808 -2234 143 1987 -1225 339 1462 FIX FIX GOOD -8 NaN NaN
1653812 -2249 146 1987 -1229 374 1459 FIX FIX GOOD -4 NaN NaN
1653816 -2253 153 1983 -1233 405 1459 FIX FIX GOOD 0 1653816 3376
1653820 -2264 159 1981 -1243 408 1455 FIX FIX GOOD 4 NaN NaN
1653824 -2285 179 1981 -1252 420 1455 FIX FIX GOOD 8 NaN NaN
1653828 -2303 204 1982 -1296 433 1455 FIX FIX GOOD 12 NaN NaN
1653832 -2338 229 1985 -1309 445 1455 FIX FIX GOOD NaN NaN NaN
1653836 -2365 241 1991 -1322 448 1456 FIX FIX GOOD -14 NaN NaN
1653840 -2378 246 1993 -1332 452 1458 FIX FIX GOOD -10 NaN NaN
1653844 -2394 248 1993 -1342 478 1461 FIX FIX GOOD -6 NaN NaN
1653848 -2416 250 1994 -1362 494 1461 FIX FIX GOOD -2 1653850 3377
1653852 -2418 269 1996 -1364 515 1461 FIX FIX GOOD 2 NaN NaN
1653856 -2419 277 1999 -1369 546 1461 FIX FIX GOOD 6 NaN NaN

70 rows × 12 columns


In [220]:
count


Out[220]:
34057

In [218]:
pd.options.display.max_rows = 600

fit-to-plane stuff


In [9]:
left_ndsref = np.array([[10, 10, 100.]]).T
right_ndsref = np.array([[7, 12, 100.]]).T

In [13]:
ipd=6.5

In [14]:
p1 = np.array([[-ipd/2, 0, 0]]).T
p2 = left_ndsref - p1
p2 = p2 / np.linalg.norm(p2)
p2 = p2 + p1

In [21]:
q1 = np.array([[ipd/2, 0, 0]]).T
q2 = right_ndsref - q1
q2 = q2 / np.linalg.norm(q2)
q2 = q2 + q1

In [52]:
X = np.matrix([[p1[0,0], p2[0,0], q1[0,0], q2[0,0]]])
Y = np.matrix([[p1[1,0], p2[1,0], q1[1,0], q2[1,0]]])
Z = np.matrix([[p1[2,0], p2[2,0], q1[2,0], q2[2,0]]])
A = Z.T

In [56]:
u = np.linalg.inv(A.T * A) * A.T * Y.T
u = np.array([[0, u, 0]])

In [61]:
p2_new = np.array([[p2[0,0], u[0,1]*p2[2,0], p2[2,0]]]).T
q2_new = np.array([[q2[0,0], u[0,1]*q2[2,0], q2[2,0]]]).T

In [62]:
q2_new = q2_new - q1
q2_new = q2_new / np.linalg.norm(q2_new)
q2_new = q2_new + q1

In [64]:
p2_new = p2_new - p1
p2_new = p2_new / np.linalg.norm(p2_new)
p2_new = p2_new + p1

In [66]:
P = np.array([[u[0,0], -1, u[0,1]]])
P = P / np.linalg.norm(P)

In [70]:
thp = np.degrees(np.arcsin(np.dot(P, p2)))
thq = np.degrees(np.arcsin(np.dot(P, q2)))

In [71]:
thp_new = np.degrees(np.arcsin(np.dot(P, p2_new)))
thq_new = np.degrees(np.arcsin(np.dot(P, q2_new)))

In [76]:
thq


Out[76]:
array([[-0.56183033]])

In [8]:
frames


Out[8]:
time press num
0 643629 0
1 643646 1
2 643679 2
3 643712 3
4 643746 4
5 643779 5
6 643812 6
7 643845 7
8 643879 8
9 643912 9
10 643946 10
11 643979 11
12 644012 12
13 644045 13
14 644079 14
15 644112 15
16 644145 16
17 644179 17
18 644212 18
19 644246 19
20 644279 20
21 644312 21
22 644345 22
23 644379 23
24 644413 24
25 644446 25
26 644479 26
27 644512 27
28 644545 28
29 644579 29
... ... ...
35727 2118297 35727
35728 2118330 35728
35729 2118363 35729
35730 2118397 35730
35731 2118430 35731
35732 2118463 35732
35733 2118497 35733
35734 2118531 35734
35735 2118564 35735
35736 2118597 35736
35737 2118630 35737
35738 2118664 35738
35739 2118697 35739
35740 2118730 35740
35741 2118764 35741
35742 2118797 35742
35743 2118830 35743
35744 2118863 35744
35745 2118897 35745
35746 2118930 35746
35747 2118963 35747
35748 2121173 35748
35749 2121189 35749
35750 2121222 35750
35751 2121256 35751
35752 2121289 35752
35753 2121322 35753
35754 2121356 35754
35755 2121389 35755
35756 2121422 35756

35757 rows × 2 columns


In [9]:
rt_data.loc[2]


Out[9]:
left right left right both target both
href x href y pupil area href x href y pupil area flag flag quality distance direction eccentricity x y horizontal version vertical version frame_time_diff frame_time frame_count
time
1980250 -741 -168 1849 657 -625 1302 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 -5 NaN NaN
1980254 -741 -171 1847 663 -620 1301 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 -1 1980255 33765
1980258 -743 -172 1845 663 -618 1294 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 3 NaN NaN
1980262 -744 -171 1844 662 -618 1294 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 7 NaN NaN
1980266 -745 -170 1842 658 -617 1294 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 11 NaN NaN
1980270 -747 -170 1838 655 -617 1291 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 NaN NaN NaN
1980274 -742 -171 1838 653 -620 1291 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 -14 NaN NaN
1980278 -738 -170 1838 652 -622 1290 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 -10 NaN NaN
1980282 -742 -168 1836 643 -622 1284 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 -6 NaN NaN
1980286 -746 -168 1836 643 -630 1279 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 -2 1980288 33766
1980290 -741 -169 1835 639 -630 1276 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 2 NaN NaN
1980294 -740 -168 1829 635 -630 1276 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 6 NaN NaN
1980298 -739 -167 1829 636 -634 1275 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 10 NaN NaN
1980302 -736 -167 1829 638 -631 1275 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 14 NaN NaN
1980306 -734 -167 1829 640 -630 1276 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 NaN NaN NaN
1980310 -736 -166 1828 641 -630 1277 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 -11 NaN NaN
1980314 -736 -165 1828 643 -629 1278 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 -7 NaN NaN
1980318 -736 -164 1828 646 -627 1280 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 -3 NaN NaN
1980322 -733 -164 1828 646 -627 1282 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 1 1980321 33767
1980326 -730 -166 1825 645 -626 1282 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 5 NaN NaN
1980330 -730 -165 1824 645 -627 1281 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 9 NaN NaN
1980334 -728 -165 1824 645 -620 1280 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 13 NaN NaN
1980338 -727 -162 1823 642 -617 1279 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 NaN NaN NaN
1980342 -727 -161 1822 644 -616 1279 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 -12 NaN NaN
1980346 -725 -160 1822 643 -616 1279 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 -8 NaN NaN
1980350 -729 -158 1822 644 -617 1278 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 -4 NaN NaN
1980354 -727 -158 1822 645 -617 1278 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 0 1980354 33768
1980358 -726 -158 1820 644 -618 1277 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 4 NaN NaN
1980362 -720 -159 1820 645 -617 1276 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 8 NaN NaN
1980366 -716 -157 1820 644 -617 1274 FIX FIX GOOD 450 0 0 0.000000 0.000000 0.000000 0.000000 12 NaN NaN
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
2233178 96 4171 1327 140 4100 976 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233182 104 4170 1327 140 4098 975 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233186 107 4171 1327 140 4098 974 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233190 111 4175 1327 141 4098 973 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233194 119 4176 1325 145 4097 972 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233198 127 4178 1325 147 4097 972 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233202 122 4176 1324 149 4097 972 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233206 118 4175 1324 150 4097 972 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233210 115 4176 1323 150 4097 972 FIX FIX BAD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233214 114 4176 1323 150 4097 969 FIX FIX BAD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233218 115 4176 1323 150 4096 968 FIX FIX BAD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233222 112 4177 1322 129 4088 968 FIX FIX BAD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233226 110 4174 1323 123 4080 969 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233230 109 4179 1324 125 4082 970 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233234 108 4177 1324 126 4085 970 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233238 108 4177 1324 129 4087 971 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233242 108 4176 1324 129 4087 971 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233246 109 4176 1323 135 4088 968 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233250 109 4177 1320 135 4088 967 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233254 109 4179 1319 142 4092 966 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233258 109 4181 1318 138 4108 966 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233262 111 4182 1318 140 4105 965 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233266 111 4183 1317 142 4102 965 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233270 111 4183 1314 143 4102 963 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233274 111 4186 1312 143 4103 962 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233278 110 4189 1312 142 4106 961 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233282 107 4190 1312 141 4106 959 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233286 96 4191 1310 138 4106 955 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233290 88 4196 1309 132 4106 955 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN
2233294 88 4196 1307 132 4106 955 FIX FIX GOOD 100 270 16 27.563736 7.903774 -15.364554 -4.519134 NaN NaN NaN

7125 rows × 19 columns


In [6]:
import json

In [25]:
d = [{"title":"radial_target_100_4","data":
     {"radial_target_starttime": 2278283, "capture_start_offset":612,
      "init_starttime":678397, "init_endtime":732606, "num_additional_frames":28}},
     {"title":"radial_target_50_4","data":
     {"radial_target_starttime": 2391324, "capture_start_offset":612,
      "init_starttime":817661, "init_endtime": 834048, "num_additional_frames":0, "last_possible_time":2407214}}
     ]

In [26]:
with open("./jsontest.json", 'w') as f:
    json.dump(d,f, indent=2)

In [27]:
!subl ./jsontest.json

In [28]:
with open("./jsontest.json", 'r') as f:
    fixup_data = json.load(f)

In [30]:
fixup_data[0]


Out[30]:
{u'data': {u'capture_start_offset': 612,
  u'init_endtime': 732606,
  u'init_starttime': 678397,
  u'num_additional_frames': 28,
  u'radial_target_starttime': 2278283},
 u'title': u'radial_target_100_4'}

In [38]:
with open("/Users/bwsprague/GradSchool/Research/BerkeleyVisionStats/data/raw/gaze/tki/tki_inside_fixup.json", 'r') as f:
    fixup_data = json.load(f)

In [39]:
fixup_data


Out[39]:
[{u'data': {u'capture_start_offset': 612,
   u'init_endtime': 732606,
   u'init_starttime': 678397,
   u'num_additional_frames': 28,
   u'radial_target_starttime': 2278283},
  u'title': u'radial_target_100_4'},
 {u'data': {u'capture_start_offset': 612,
   u'init_endtime': 834048,
   u'init_starttime': 817661,
   u'last_possible_time': 2407214,
   u'num_additional_frames': 0,
   u'radial_target_starttime': 2391324},
  u'title': u'radial_target_50_4'}]

In [ ]:
def fixup_frame_sync(frames, fixup_fpath):
    import json
    
    with open(fixup_fpath, 'r') as f:
        fixup_info = json.load(f)
        
    for info in fixup_info:
        data = info["data"]
        startframe = data["radial_target_starttime"]