JeVoisBase  1.22
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Loading...
Searching...
No Matches
base_dataloader.py
Go to the documentation of this file.
1import os
2
3import cv2 as cv
4
6 def __init__(self, **kwargs):
7 self._path = kwargs.pop('path', None)
8 assert self._path, 'Benchmark[\'data\'][\'path\'] cannot be empty.'
9
10 self._files = kwargs.pop('files', None)
11 assert self._files, 'Benchmark[\'data\'][\'files\'] cannot be empty'
12 self._len_files = len(self._files)
13
14 self._sizes = kwargs.pop('sizes', [[0, 0]])
15 self._len_sizes = len(self._sizes)
16
17 @property
18 def name(self):
19 return self.__class__.__name__
20
21 def __len__(self):
22 return self._len_files * self._len_sizes
23
24 def __iter__(self):
25 for filename in self._files:
26 image = cv.imread(os.path.join(self._path, filename))
27 if [0, 0] in self._sizes:
28 yield filename, image
29 else:
30 for size in self._sizes:
31 image_r = cv.resize(image, size)
32 yield filename, image_r
33
35 def __init__(self, filepath):
36 self._filepath = filepath
37 self._video = cv.VideoCapture(self._filepath)
38
39 def __iter__(self):
40 while True:
41 has_frame, frame = self._video.read()
42 if has_frame:
43 yield frame
44 else:
45 break
46
47 def __next__(self):
48 while True:
49 has_frame, frame = self._video.read()
50 if has_frame:
51 return frame
52 else:
53 break
54
55 def reload(self):
56 self._video = cv.VideoCapture(self._filepath)
57
58 def getFrameSize(self):
59 w = int(self._video.get(cv.CAP_PROP_FRAME_WIDTH))
60 h = int(self._video.get(cv.CAP_PROP_FRAME_HEIGHT))
61 return [w, h]
62
63
65 def __init__(self, **kwargs):
66 self._path = kwargs.pop('path', None)
67 assert self._path, 'Benchmark[\'data\'][\'path\'] cannot be empty.'
68
69 self._files = kwargs.pop('files', None)
70 assert self._files,'Benchmark[\'data\'][\'files\'] cannot be empty.'
71
72 self._streams = dict()
73 for filename in self._files:
74 self._streams[filename] = _VideoStream(os.path.join(self._path, filename))
75
76 @property
77 def name(self):
78 return self.__class__.__name__
79
80 def __len__(self):
81 return len(self._files)
82
83 def __getitem__(self, idx):
84 return self._files[idx], self._streams[idx]