JeVoisBase
1.22
JeVois Smart Embedded Machine Vision Toolkit Base Modules
Share this page:
Tweet
Loading...
Searching...
No Matches
base_dataloader.py
Go to the documentation of this file.
1
import
os
2
3
import
cv2
as
cv
4
5
class
_BaseImageLoader
:
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
34
class
_VideoStream
:
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
64
class
_BaseVideoLoader
:
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]
utils.dataloaders.base_dataloader._BaseImageLoader
Definition
base_dataloader.py:5
utils.dataloaders.base_dataloader._BaseImageLoader._path
_path
Definition
base_dataloader.py:7
utils.dataloaders.base_dataloader._BaseImageLoader.name
name(self)
Definition
base_dataloader.py:18
utils.dataloaders.base_dataloader._BaseImageLoader._len_files
_len_files
Definition
base_dataloader.py:12
utils.dataloaders.base_dataloader._BaseImageLoader._sizes
_sizes
Definition
base_dataloader.py:14
utils.dataloaders.base_dataloader._BaseImageLoader.__iter__
__iter__(self)
Definition
base_dataloader.py:24
utils.dataloaders.base_dataloader._BaseImageLoader._files
_files
Definition
base_dataloader.py:10
utils.dataloaders.base_dataloader._BaseImageLoader._len_sizes
_len_sizes
Definition
base_dataloader.py:15
utils.dataloaders.base_dataloader._BaseImageLoader.__init__
__init__(self, **kwargs)
Definition
base_dataloader.py:6
utils.dataloaders.base_dataloader._BaseImageLoader.__len__
__len__(self)
Definition
base_dataloader.py:21
utils.dataloaders.base_dataloader._BaseVideoLoader
Definition
base_dataloader.py:64
utils.dataloaders.base_dataloader._BaseVideoLoader.__len__
__len__(self)
Definition
base_dataloader.py:80
utils.dataloaders.base_dataloader._BaseVideoLoader._streams
_streams
Definition
base_dataloader.py:72
utils.dataloaders.base_dataloader._BaseVideoLoader.name
name(self)
Definition
base_dataloader.py:77
utils.dataloaders.base_dataloader._BaseVideoLoader._files
_files
Definition
base_dataloader.py:69
utils.dataloaders.base_dataloader._BaseVideoLoader.__getitem__
__getitem__(self, idx)
Definition
base_dataloader.py:83
utils.dataloaders.base_dataloader._BaseVideoLoader._path
_path
Definition
base_dataloader.py:66
utils.dataloaders.base_dataloader._BaseVideoLoader.__init__
__init__(self, **kwargs)
Definition
base_dataloader.py:65
utils.dataloaders.base_dataloader._VideoStream
Definition
base_dataloader.py:34
utils.dataloaders.base_dataloader._VideoStream.getFrameSize
getFrameSize(self)
Definition
base_dataloader.py:58
utils.dataloaders.base_dataloader._VideoStream.__init__
__init__(self, filepath)
Definition
base_dataloader.py:35
utils.dataloaders.base_dataloader._VideoStream._video
_video
Definition
base_dataloader.py:37
utils.dataloaders.base_dataloader._VideoStream.__iter__
__iter__(self)
Definition
base_dataloader.py:39
utils.dataloaders.base_dataloader._VideoStream.reload
reload(self)
Definition
base_dataloader.py:55
utils.dataloaders.base_dataloader._VideoStream.__next__
__next__(self)
Definition
base_dataloader.py:47
utils.dataloaders.base_dataloader._VideoStream._filepath
_filepath
Definition
base_dataloader.py:36
opencv_zoo
benchmark
utils
dataloaders
base_dataloader.py
Please help us improve this page: Edit it on
GitHub
or
email us your edits and suggestions.
Generated by
1.9.8