Represents an image that is backed by native resources and can be created from various sources.
More...
|
|
| __init__ (self, bytes unique_id) |
| | Creates an ImageRef from a unique id and acquires strong reference to the image.
|
| |
|
'ImageRef' | __enter__ (self) |
| | Context manager interface.
|
| |
| None | __exit__ (self, Any exc_type, Any exc_val, Any exc_tb) |
| | Context manager interface.
|
| |
| 'ImageRef' | from_ndarray (cls, np.ndarray image, RawImageLoadOptions options) |
| | Creates an ImageRef from a numpy array.
|
| |
| 'ImageRef' | from_path (cls, Union[str, Path] path, Optional[PathImageLoadOptions] options=None) |
| | Creates an image from the given path with given options.
|
| |
| 'ImageRef' | from_encoded_buffer (cls, bytes buffer, Optional[BufferImageLoadOptions] options=None) |
| | Creates an image from the given encoded buffer with given options.
|
| |
| None | save_image (self, Union[str, Path] path, Optional[SaveImageOptions] options=None) |
| | Saves the image to the given path with the given options.
|
| |
| bytes | encode (self, Optional[EncodeImageOptions] options=None) |
| | Encodes the image to a buffer with the given options.
|
| |
| np.ndarray | to_ndarray (self) |
| | Converts the image to a numpy array.
|
| |
| ImageInfo | info (self) |
| | Returns the image info.
|
| |
| None | release (self) |
| | Releases the image reference.
|
| |
|
|
None | release_all_images () |
| | Releases all alive images.
|
| |
Represents an image that is backed by native resources and can be created from various sources.
◆ __exit__()
| None __exit__ |
( |
| self, |
|
|
Any | exc_type, |
|
|
Any | exc_val, |
|
|
Any | exc_tb ) |
Context manager interface.
Effectively calls release on exit.
◆ encode()
Encodes the image to a buffer with the given options.
- Parameters
-
| options | options used during encoding |
- Returns
- encoded image data
◆ from_encoded_buffer()
Creates an image from the given encoded buffer with given options.
- Parameters
-
| buffer | encoded image data |
| options | options used during image loading |
- Returns
- ImageRef created from the given encoded buffer
◆ from_ndarray()
Creates an ImageRef from a numpy array.
The method creates a copy of the image data. If the image ref is created from an array that comes from a live source (e.g. camera), it is recommended to use the ImageRef as a context manager to ensure that the image data is released as soon as possible.
- Parameters
-
| image | The image data as a numpy array. The image must be of type np.uint8 and be in a GRAY or BGR format. |
| options | The options to use for loading the image. It is important to specify live_source in the options correctly as it often has significant impact on the scanner to which the image is passed performance. |
- Returns
- : The created ImageRef.
◆ from_path()
Creates an image from the given path with given options.
- Parameters
-
| path | path to the image file |
| options | options used during image loading |
- Returns
- ImageRef created from the given path
◆ info()
Returns the image info.
- Returns
- image information
◆ release()
Releases the image reference.
The call should be made to release the image reference as soon as it is no longer needed. If not called, the image reference will be released when the ImageRef object is garbage collected. When using CPython, garbage collection uses reference counting and so calls to the object finalizer are deterministic. When creating the ImageRef from a live source we recommend using the context manager interface (which effectively calls this method on exit) to ensure that the image data is released as soon as possible.
◆ save_image()
| None save_image |
( |
| self, |
|
|
Union[str, Path] | path, |
|
|
Optional[SaveImageOptions] | options = None ) |
Saves the image to the given path with the given options.
- Parameters
-
| path | path to the image file |
| options | options used during saving |
- Returns
- ImageRef created from the given path
◆ to_ndarray()
| np.ndarray to_ndarray |
( |
| self | ) |
|
Converts the image to a numpy array.
If the image is colorful, the array will be in BGR format.
The documentation for this class was generated from the following file: