Data files
Access data file shipped with the Toolbox.
- machinevisiontoolbox.base.data.mvtb_load_matfile(filename)[source]
Load toolbox mat format data file
- Parameters:
filename (str) – relative pathname of datafile
- Raises:
ValueError – File does not exist
- Returns:
contents of mat data file
- Return type:
dict
Reads a MATLAB format mat file which can contain multiple variables, in a binary or ASCII format. Returns a dict where the keys are the variable names and the values are NumPy arrays.
Note
Uses SciPy
io.loadmat
to do the work.If the filename has no path component it will be first be looked for in the folder
machinevisiontoolbox/data
, then the current working directory.
- Seealso:
- machinevisiontoolbox.base.data.mvtb_load_jsonfile(filename)[source]
Load toolbox JSON format data file
- Parameters:
filename (str) – relative pathname of datafile
- Raises:
ValueError – File does not exist
- Returns:
contents of JSON data file
- Return type:
dict
Reads a JSON format file which can contain multiple variables and return a dict where the keys are the variable names and the values are Python data types.
Note
If the filename has no path component it will be first be looked for in the folder
machinevisiontoolbox/data
, then the current working directory.
- Seealso:
- machinevisiontoolbox.base.data.mvtb_load_data(filename, handler, **kwargs)[source]
Load toolbox data file
- Parameters:
filename (str) – relative pathname of datafile
handler (callable) – function to read data
- Raises:
ValueError – File does not exist
- Returns:
data object
Resolves the relative pathname to an absolute name and then invokes the data reading function:
handler(abs_file_name, **kwargs)
For example:
data = mvtb_load_data('data/foo.dat', lambda f: data_load(open(f, 'r')))
Note
If the filename has no path component it will first be looked for in the folder
machinevisiontoolbox/data
, then the current working directory.- Seealso:
- machinevisiontoolbox.base.data.mvtb_path_to_datafile(*filename, local=True, string=False)[source]
Get absolute path to file in MVTB data package
- Parameters:
filename (str) – pathname of image file
local (bool) – search for file locally first, default True
- Raises:
FileNotFoundError – File does not exist
- Returns:
Absolute path
- Return type:
Path
The data associated with the Machine Vision Toolbox for Python is shipped as a separate package.
The positional arguments are joined, like
os.path.join
, for example:mvtb_path_to_datafile('data', 'solar.dat') # data/solar.dat
If
local
is True then~
is expanded and if the file exists, the path is made absolute, and symlinks resolved:mvtb_path_to_datafile('foo.dat') # find ./foo.dat mvtb_path_to_datafile('~/foo.dat') # find $HOME/foo.dat
Otherwise, the file is sought within the
mvtbdata
package and if found, return that absolute path.Example:
>>> from machinevisiontoolbox import mvtb_path_to_datafile >>> mvtb_path_to_datafile('data', 'solar.dat') # read mvtbdata/data/solar.dat PosixPath('/opt/hostedtoolcache/Python/3.9.16/x64/lib/python3.9/site-packages/mvtbdata/data/solar.dat')