-
Notifications
You must be signed in to change notification settings - Fork 9
/
datasets.py
38 lines (31 loc) · 1.14 KB
/
datasets.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import os
import numpy as np
def load_utiris():
"""Fetches NIR images from UTIRIS dataset.
Retrieves image paths and labels for each NIR image in the dataset. There should already exist a directory named
'UTIRIS V.1'. If it does not exist then download the dataset from the official page (https://utiris.wordpress.com/).
:return: A dictionary with two keys: 'data' contains all images paths, 'target' contains the image labels - each eye
gets its unique number.
"""
data = []
target = []
target_i = 0
index_used = False
for dirpath, dirnames, filenames in os.walk('UTIRIS V.1\\Infrared Images'):
for f in filenames:
if f.endswith('.bmp'):
data.append('{}\{}'.format(dirpath, f))
target.append(target_i)
index_used = True
if index_used:
target_i += 1
index_used = False
return {'data': np.array(data),
'target': np.array(target)}
# Example usage
if __name__ == '__main__':
import cv2
data = load_utiris()['data']
image = cv2.imread(data[0])
cv2.imshow('test', image)
cv2.waitKey(0)