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 = 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 I = cv2.imread(os.path.join(PATH_IMAGES, imName_full), 0)
for name in list_ds: # 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) Data['Images'].append(I) keydict['resolution'].append(I.shape) keydict['archive'].append(ds_name) pupil_loc = PupilData[fr_num, :] keydict['pupil_loc'].append(pupil_loc) Data['pupil_loc'].append(pupil_loc) Data['Info'].append(str(fr_num)) fr_num += 1
canvas.start_event_loop(interval) return def fix_pupil_loc(p, res): # res: [H, W] p[0] = 0.5 * p[0] p[1] = res[0] - 0.5 * p[1] return p for name in list_ds: # Ignore the first row and column. # Columns: [index, p_x, p_y] Data, keydict = generateEmptyStorage(name='PupilNet', subset=name) ds_name = 'PupilNet_{}_{}'.format(name, ds_num) 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))) # Create an empty dictionary as per agreed structure Data['pupil_loc'] = PupilData[:, 1:] * sc keydict['pupil_loc'] = PupilData[:, 1:] * sc
for name in 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]
list_ds = [ele for ele in os.listdir(PATH_DIR) if os.path.isdir(os.path.join(PATH_DIR, ele))] list_ds.remove('3d') for fName in list_ds: 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_general', subset='riteyes_general_'+fName) ds_name = 'riteyes_general_{}_{}'.format(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'))
for fName in list_ds: warnings.filterwarnings("error") ds_name = 'NVGaze' + '_' + fName + '_' + str(ds_num) # 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)