Scanbot SDK
Loading...
Searching...
No Matches
ImageRef

Represents an image that is backed by native resources and can be created from various sources. More...

Public Member Functions

 __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.
 
'ImageReffrom_ndarray (cls, np.ndarray image, RawImageLoadOptions options)
 Creates an ImageRef from a numpy array.
 
'ImageReffrom_path (cls, Union[str, Path] path, Optional[PathImageLoadOptions] options=None)
 Creates an image from the given path with given options.
 
'ImageReffrom_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.
 

Static Public Member Functions

None release_all_images ()
 Releases all alive images.
 

Detailed Description

Represents an image that is backed by native resources and can be created from various sources.

Member Function Documentation

◆ __exit__()

None __exit__ ( self,
Any exc_type,
Any exc_val,
Any exc_tb )

Context manager interface.

Effectively calls release on exit.

◆ encode()

bytes encode ( self,
Optional[EncodeImageOptions] options = None )

Encodes the image to a buffer with the given options.

Parameters
optionsoptions used during encoding
Returns
encoded image data

◆ from_encoded_buffer()

'ImageRef' from_encoded_buffer ( cls,
bytes buffer,
Optional[BufferImageLoadOptions] options = None )

Creates an image from the given encoded buffer with given options.

Parameters
bufferencoded image data
optionsoptions used during image loading
Returns
ImageRef created from the given encoded buffer

◆ from_ndarray()

'ImageRef' from_ndarray ( cls,
np.ndarray image,
RawImageLoadOptions options )

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
imageThe image data as a numpy array. The image must be of type np.uint8 and be in a GRAY or BGR format.
optionsThe 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()

'ImageRef' from_path ( cls,
Union[str, Path] path,
Optional[PathImageLoadOptions] options = None )

Creates an image from the given path with given options.

Parameters
pathpath to the image file
optionsoptions used during image loading
Returns
ImageRef created from the given path

◆ info()

ImageInfo info ( self)

Returns the image info.

Returns
image information

◆ release()

None release ( self)

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
pathpath to the image file
optionsoptions 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: