/
frame.py
112 lines (82 loc) · 2.89 KB
/
frame.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
"""Contains the Frame class."""
from pathlib import Path
import _zivid
import zivid._settings_converter as _settings_converter
import zivid._camera_state_converter as _camera_state_converter
import zivid._frame_info_converter as _frame_info_converter
from zivid.point_cloud import PointCloud
class Frame: # pylint: disable=too-few-public-methods
"""A frame captured by a Zivid camera."""
def __init__(self, file_name):
"""Create a frame by loading data from a file.
Args:
file_name: a pathlib.Path instance or a string
Raises:
TypeError: unsupported type provided for file name
"""
if isinstance(file_name, (str, Path)):
self.__impl = _zivid.Frame(str(file_name))
elif isinstance(file_name, _zivid.Frame):
self.__impl = file_name
else:
raise TypeError(
"Unsupported type for argument file_name. Got {}, expected {} or {}.".format(
type(file_name).__name__, str.__name__, Path.__name__
)
)
def __str__(self):
return str(self.__impl)
def get_point_cloud(self):
"""Copy the point cloud to the CPU and returns it.
Returns:
a point cloud instance
"""
return PointCloud(self.__impl.get_point_cloud())
def save(self, file_path):
"""Save the frame to file. The file type is determined from the file extension.
Args:
file_path: destination path
"""
self.__impl.save(str(file_path))
def load(self, file_path):
"""Load a frame from a Zivid data file.
Args:
file_path: path to zdf file
"""
self.__impl.load(str(file_path))
@property
def settings(self):
"""Get the settings for the API at the time of the frame capture.
Returns:
a settings instance
"""
return _settings_converter.to_settings( # pylint: disable=protected-access
self.__impl.settings
)
@property
def state(self):
"""Get the camera state data at the time of the frame capture.
Returns:
a camera state instance
"""
return _camera_state_converter.to_camera_state( # pylint: disable=protected-access
self.__impl.state
)
@property
def info(self):
"""Get information collected at the time of the frame capture.
Returns:
a camera info instance
"""
return _frame_info_converter.to_info( # pylint: disable=protected-access
self.__impl.info
)
def release(self):
"""Release the underlying resources."""
self.__impl.release()
def __enter__(self):
return self
def __exit__(self, exception_type, exception_value, traceback):
self.release()
def __del__(self):
self.release()