for subject_id, name in enumerate(list_ds): # Ignore the first row and column. # Columns: [index, p_x, p_y] # Read pupil data from the published dataset PupilData = np.genfromtxt(os.path.join(PATH_DIR, name + '.txt'), delimiter=' ')[1:, 1:] listFiles = glob.glob(os.path.join(PATH_DIR, name, '*.png')) imNames = list(map(os.path.basename, listFiles)) imNames = list(map(os.path.splitext, imNames)) imNames, _ = list(zip(*imNames)) imNames = np.array(list(map(int, imNames))) # Generate an empty data container Data, keydict = generateEmptyStorage(name='Fuhl', subset=name) ds_name = keydict['dataset'] + '_' + keydict['subset'] + '_' + str(ds_num) if not noDisp: fig, plts = plt.subplots(1, 1) for i in range(0, PupilData.shape[0]): iNum = PupilData[i, 0] # Assert unique image names loc = imNames == iNum assert sum(loc) == 1, "Error. Only one file should have that number" loc = np.where(loc)[0] path2im = listFiles[int(loc)] imStr = os.path.split(path2im)[1]
def process(args, ds_num, fName): warnings.filterwarnings("error") PATH_IMAGES = os.path.join(PATH_DIR, fName, 'synthetic') PATH_MASK_SKIN = os.path.join(PATH_DIR, fName, 'mask-withskin') PATH_MASK_NOSKIN = os.path.join(PATH_DIR, fName, 'mask-withoutskin-noglasses') imList = glob.glob(os.path.join(PATH_IMAGES, '*.tif')) if not noDisp: fig, plts = plt.subplots(1, 1) Data, keydict = generateEmptyStorage( name='riteyes-{}'.format(args.which_riteyes_set), subset='riteyes-{}_{}'.format(args.which_riteyes_set, fName)) ds_name = 'riteyes-{}_{}_{}'.format(args.which_riteyes_set, fName, ds_num) fr_num = 0 for ele in imList: imName_withext = os.path.split(ele)[1] imName = os.path.splitext(ele)[0] path2im = os.path.join(PATH_IMAGES, imName_withext) path2mask = os.path.join(PATH_MASK_SKIN, imName_withext) path2mask_woskin = os.path.join(PATH_MASK_NOSKIN, imName_withext) try: I = np.asarray(Image.open(path2im).convert('L')) maskIm = np.asarray(Image.open(path2mask).convert('RGB')) maskIm_woskin = np.asarray( Image.open(path2mask_woskin).convert('RGB')) I = cv2.resize(I, (640, 480), interpolation=cv2.INTER_CUBIC) maskIm = cv2.resize(maskIm, (640, 480), interpolation=cv2.INTER_NEAREST) maskIm_woskin = cv2.resize(maskIm_woskin, (640, 480), interpolation=cv2.INTER_NEAREST) maskIm, maskIm_woskin = quantizeMask(maskIm, maskIm_woskin) except: print('Corrupt data found in {}.'.format(ele)) import pdb pdb.set_trace() pupilPts, irisPts = getValidPoints(maskIm_woskin) # Pupil ellipse fit model_pupil = ransac(pupilPts, ElliFit, 15, 40, 5e-3, 15).loop() pupil_fit_error = my_ellipse(model_pupil.model).verify(pupilPts) r, c = np.where(maskIm_woskin == 2) pupil_loc = model_pupil.model[: 2] if pupil_fit_error < 0.05 else np.stack( [np.mean(c), np.mean(r)], axis=0) # Iris ellipse fit model_iris = ransac(irisPts, ElliFit, 15, 40, 5e-3, 15).loop() iris_fit_error = my_ellipse(model_iris.model).verify(irisPts) if (pupil_fit_error > 0.05) | (iris_fit_error > 0.05): print('Skipping: {}'.format(imName)) continue Data['Info'].append(imName) Data['Masks'].append(maskIm) Data['Images'].append(I) Data['pupil_loc'].append(pupil_loc) Data['subject_id'].append(str(fName)) Data['Masks_noSkin'].append(maskIm_woskin) keydict['archive'].append(ds_name) keydict['pupil_loc'].append(pupil_loc) keydict['resolution'].append(I.shape) keydict['subject_id'].append(str(fName)) Data['Fits']['pupil'].append(model_pupil.model) Data['Fits']['iris'].append(model_iris.model) keydict['Fits']['pupil'].append(model_pupil.model) keydict['Fits']['iris'].append(model_iris.model) fr_num += 1 if not noDisp: if fr_num == 1: cE = Ellipse(tuple(pupil_loc), 2 * model_pupil.model[2], 2 * model_pupil.model[3], angle=np.rad2deg(model_pupil.model[-1])) cL = Ellipse(tuple(model_iris.model[0:2]), 2 * model_iris.model[2], 2 * model_iris.model[3], np.rad2deg(model_iris.model[4])) cE.set_facecolor('None') cE.set_edgecolor((1.0, 0.0, 0.0)) cL.set_facecolor('None') cL.set_edgecolor((0.0, 1.0, 0.0)) cI = plts.imshow(I) cM = plts.imshow(maskIm, alpha=0.5) cX = plts.scatter(pupil_loc[0], pupil_loc[1]) plts.add_patch(cE) plts.add_patch(cL) plt.show() plt.pause(.01) else: cE.center = tuple(pupil_loc) cE.angle = np.rad2deg(model_pupil.model[-1]) cE.width = 2 * model_pupil.model[2] cE.height = 2 * model_pupil.model[3] cL.center = tuple(model_iris.model[0:2]) cL.width = 2 * model_iris.model[2] cL.height = 2 * model_iris.model[3] cL.angle = np.rad2deg(model_iris.model[-1]) newLoc = np.array([pupil_loc[0], pupil_loc[1]]) cI.set_data(I) cM.set_data(maskIm) cX.set_offsets(newLoc) mypause(0.01) keydict['resolution'] = np.stack(keydict['resolution'], axis=0) keydict['subject_id'] = np.stack(keydict['subject_id'], axis=0) keydict['archive'] = np.stack(keydict['archive'], axis=0) keydict['pupil_loc'] = np.stack(keydict['pupil_loc'], axis=0) keydict['Fits']['pupil'] = np.stack(keydict['Fits']['pupil'], axis=0) keydict['Fits']['iris'] = np.stack(keydict['Fits']['iris'], axis=0) Data['subject_id'] = np.stack(Data['subject_id'], axis=0) Data['pupil_loc'] = np.stack(Data['pupil_loc'], axis=0) Data['Images'] = np.stack(Data['Images'], axis=0) Data['Masks'] = np.stack(Data['Masks'], axis=0) Data['Masks_noSkin'] = np.stack(Data['Masks_noSkin'], axis=0) Data['Fits']['pupil'] = np.stack(Data['Fits']['pupil'], axis=0) Data['Fits']['iris'] = np.stack(Data['Fits']['iris'], axis=0) warnings.filterwarnings("ignore") # Save data dd.io.save(os.path.join(PATH_DS, str(ds_name) + '.h5'), Data) scio.savemat(os.path.join(PATH_MASTER, str(ds_name) + '.mat'), keydict, appendmat=True) ds_num = ds_num + 1
for name in list_ds: # Ignore the first row and column. # Columns: [index, p_x, p_y] opts = os.listdir(os.path.join(PATH_DIR, name)) for subdir in opts: PATH_DATA = os.path.join(PATH_DIR, name, subdir) # Read pupil data Path2text = os.path.join(PATH_DATA, 'journal-{:04d}.txt'.format(int(subdir)-1)) Path2vid = os.path.join(PATH_DATA, 'eye-{:04d}-0000.avi'.format(int(subdir)-1)) PupilData = np.array(readFormattedText(Path2text, 2)) VidObj = cv2.VideoCapture(Path2vid) # Create an empty dictionary as per agreed structure Data, keydict = generateEmptyStorage(name='Santini', subset='Santini_{}'.format(name)) ds_name = keydict['dataset'] + '_' + keydict['subset'] + '_' + str(ds_num) if not noDisp: fig, plts = plt.subplots(1,1) fr_num = 0 while(VidObj.isOpened()): ret, I = VidObj.read() if ret == True: I = cv2.cvtColor(I, cv2.COLOR_BGR2GRAY) I = cv2.resize(I, (640, 480), cv2.INTER_LANCZOS4) Data['Images'].append(I)
ds_name = 'NVGaze' + '_' + fName + '_' + str(ds_num) # Parse subject ID from the name subject_id = fName.split('_')[2] # Ignore the first row and column. # Columns: [index, p_x, p_y] ZipObj = zipfile.ZipFile( os.path.join(PATH_DIR, fName, 'footage_image_data.zip')) imList = [ele for ele in ZipObj.namelist() if 'type_img_frame' in ele] shuffle(imList) if not noDisp: fig, plts = plt.subplots(1, 1) Data, keydict = generateEmptyStorage(name='NVGaze', subset=fName) fr_num = 0 for boo in imList[:500]: # Read pupil info imNum_str = re.findall('\d+', boo)[0] str_imName = 'type_img_frame_{}.png'.format(imNum_str) str_imName_Mask = 'type_maskWithSkin_frame_{}.png'.format(imNum_str) str_imName_Mask_woSkin = 'type_maskWithoutSkin_frame_{}.png'.format( imNum_str) I = ZipObj.read(str_imName) I = np.array(Image.open(io.BytesIO(I))).astype(np.double) I = preProcessNV(I, np.uint8, 0.5)
listDir.remove('test') for dirCond in listDir: ds_name = 'OpenEDS_{}_{}'.format(dirCond, ds_num) print('Opening the {} folder'.format(dirCond)) # Read UID path2json = os.path.join(PATH_OPENEDS, 'OpenEDS_{}_userID_mapping_to_images.json'.format(dirCond)) im2UID = json.load(open(path2json, 'r')) PATH_IMAGES = os.path.join(PATH_DIR, dirCond, 'images') PATH_LABELS = os.path.join(PATH_DIR, dirCond, 'labels') PATH_FITS = os.path.join(PATH_DIR, dirCond, 'fits') listIm = os.listdir(PATH_IMAGES) Data, keydict = generateEmptyStorage(name='OpenEDS', subset=dirCond) i = 0 if not noDisp: fig, plts = plt.subplots(1,1) for pData in im2UID: # Image number and UID for each person listIm = pData['semantic_segmenation_images'] pid = str(int(pData['id'].replace('U', '')) - 111) for imName_full in listIm: imName, _ = os.path.splitext(imName_full) # Do not save images without a proper ellipse and iris fit # Load image, label map and fits
# Ignore the first row and column. # Columns: [index, p_x, p_y] opts = glob.glob(os.path.join(PATH_DIR, name, '*.avi')) for Path2vid in opts: # Read pupil info loc, fName = os.path.split(Path2vid) fName = os.path.splitext(fName)[0] Path2text = os.path.join(loc, fName + '.txt') PupilData = np.array(readFormattedText(Path2text, 0)) VidObj = cv2.VideoCapture(Path2vid) ds_name = ds_name = 'LPW_{}_{}_{}'.format(name, fName, ds_num) # Generate empty dictionaries Data, keydict = generateEmptyStorage(name='LPW', subset='LPW_{}'.format(name)) if not noDisp: fig, plts = plt.subplots(1, 1) fr_num = 0 while (VidObj.isOpened()): ret, I = VidObj.read() if ret == True: I = cv2.cvtColor(I, cv2.COLOR_BGR2GRAY) pupil_loc = PupilData[fr_num, :] Data['Info'].append(str(fr_num)) Data['Images'].append(I) Data['pupil_loc'].append(pupil_loc) Data['subject_id'].append(str(subject_id))
N = 2000 opSize = (640, 480) sc = 3 # Modify this to control how much to extract # x_sc = int(sc*opSize[0]) # y_sc = int(sc*opSize[1]) # x_crop = int(0.5*x_sc) # y_crop = int(0.5*y_sc) for i in range(0, 10): ds_name = 'UnityEyes_' + str(i) + '_' + str(ds_num) Image_counter = 0.0 if not args.noDisp: fig, plts = plt.subplots(1, 1) Data, keydict = generateEmptyStorage(name='UnityEyes', subset='UnityEyes_{}'.format(i)) for fName in list_ds[i * N:(i + 1) * N]: path2im = os.path.split(fName)[0] imNum = os.path.splitext(os.path.split(fName)[1])[0] Info = json.load(open(os.path.join(path2im, imNum + '.json'), 'r')) subject_id = Info['eye_region_details']['primary_skin_texture'] # Read image I = cv2.imread(fName, 0)[:, 480:-480, ...] # Read sclera points pts_sclera = [ np.asarray(literal_eval(ele)) for ele in Info['interior_margin_2d'] ]
for fName in list_ds: warnings.filterwarnings("error") ds_name = 'Swirski'+'_'+fName+'_'+str(ds_num) # Parse subject ID from the name subject_id = str(fName.split('-')[0]) # Ignore the first row and column. # Columns: [index, p_x, p_y] imList = os.listdir(os.path.join(PATH_DIR, fName, 'frames')) imList.sort() if not noDisp: fig, plts = plt.subplots(1,1) Data, keydict = generateEmptyStorage(name='Swirski', subset='Swirski_'+fName) # Read annotations info = pd.read_csv(os.path.join(PATH_DIR, fName, 'pupil-ellipses.txt'), delimiter=' ') ellipses = info.iloc[:, 2:].to_numpy() frame_no = info.iloc[:, 0].to_numpy() fr_num = 0 for idx, entry in np.ndenumerate(frame_no): path_im = os.path.join(PATH_DIR, fName, 'frames', '{}-eye.png'.format(entry)) I = cv2.imread(path_im, 0) # Pad 10 replicated pixels to bring to 640x480 I = np.pad(I, ((10, 10), (10, 10)), mode='edge')