Image
Image and image data/metadata returned by cameras.
Classes:
An image and its data and metadata. |
|
Represents some metadata about the raw |
|
Represents object location inference data from a |
- class Image
Bases:
object
An image and its data and metadata.
Warning
Do not create a
Image
manually, rather get an image from e.g.create_empty()
,create_image()
,deep_copy_image()
, or from a camera with e.g.get_next_image()
.Methods:
Converts the image to a new pixel format and optionally using a specific algorithm and returns a new image.
Copies the image data into an existing buffer, such as a numpy array or a bytearray that can be re-used.
Creates and returns an empty image with no data or data buffers.
Creates and returns an image with some pre-set properties.
Copies the given image into this image.
Creates and returns an image by copying all the data from the other image so they don't share buffers.
Gets the number of bits used per pixel in the image.
Gets the size of the buffer associated with the image in bytes.
Returns a
ImageChunkData
of the image.Gets the color processing algorithm of this image.
Returns whether this image was incomplete.
Gets the default number of threads used for image decompression during
convert()
.Returns whether the computed checksum matches with chunk data's ImageCRC.
Get the value which no image data will exceed.
Get the value which no image data will be less than.
Gets the default color processing algorithm of all images (if not otherwise set).
Gets the image's acquisition frame ID.
Gets the time stamp for the image in nanoseconds.
Gets the height of the image in pixels.
Gets and copies the image data and returns it as a bytearray.
Gets the image data as a memory view of the underlying data without copying.
Gets the size of the image and just the image - not including any additional payloads with the image.
Gets a unique ID for this image.
Returns whether the image is still in use by the stream.
Returns whether this image is compressed.
Returns the id of the chunk data layout.
Gets the number of channels (depth) used in the image.
Gets the ROI x offset in pixels for this image.
Gets the ROI y offset in pixels for this image.
Gets the x padding in bytes for this image.
Gets the y padding in bytes for this image.
Gets the payload type that was transmitted.
Gets the image's pixel format.
Gets the image's integer type used in the pixel format of this image.
Returns a string value that represents this image's pixel format.
Returns data integrity status of the image when it was returned from
get_next_image()
.Returns a string describing the meaning of the status string from
get_status()
.Gets the stride of the image in bytes.
Gets the GenTL specific payload type that was transmitted.
Gets the pixel format of the image.
Gets the image's underlying transport layer namespace in which this image's TL specific pixel format resides.
Gets the size of valid data in the image payload.
Gets the width of the image in pixels.
Returns whether the image contains ImageCRC checksum from the chunk data.
Release the image and its data for images gotten with
get_next_image()
.Sets new dimensions of the image object and allocates memory if needed.
Saves the image to a bmp file.
Saves the image to a file, depending on the format specified.
Saves the image to a JPEG file.
Saves the image to a JPEG2000 file.
Saves the image to a pgm file.
Saves the image to a png file.
Saves the image to a ppm file.
Saves the image to a tiff file.
Sets the default number of threads used for image decompression during
convert()
.Sets the default color processing algorithm of all images (if not otherwise set).
- convert_fmt(self, unicode pix_fmt, unicode algorithm=u'', Image dest=None) Image
Converts the image to a new pixel format and optionally using a specific algorithm and returns a new image.
- Parameters
pix_fmt – The pixel format name string from
PixelFormat_names
.algorithm – An optional algorithm name string from
color_processing_algo_names
. If empty it’s not set.dest – Optional destination image where the converted output result will be stored. The destination image buffer size must be sufficient to store the converted image data.
- Returns
A new
Image
ifdest
was not provided, otherwisedest
.
Note
Compressed images are decompressed before any further color processing or conversion during this call. Decompression is multi-threaded and defaults to utilizing one less than the number of concurrent threads supported by the system. It uses the number set in
set_compression_threads()
, if set.
- copy_image_data(self, unsigned char[:] buffer)
Copies the image data into an existing buffer, such as a numpy array or a bytearray that can be re-used.
The buffer must be at least as large as the image data and must be able to be used as a memory view of a unsigned bytes array.
This does not include any additional payload data included with the image. For compressed images, the full image may be larger once decompressed.
For example:
>>> image = Image.create_image(640, 480, 0, 0, 'Mono16') >>> buffer = bytearray(b'
- static create_image(int width, int height, int x_offset, int y_offset, unicode pix_fmt, data=None, unicode data_type=u'', size_t data_len=0) Image
Creates and returns an image with some pre-set properties.
- Parameters
width – The image width.
height – The image height.
x_offset – The x-offset of the start of the image.
y_offset – The y-offset of the start of the image.
pix_fmt – The pixel format name string from
PixelFormat_names
.data – An optional bytes buffer or array containing the data to initialize the image with. If None, data is not set.
data_type – The payload type of the data as named in
payload_type_names
(such as compressed). See alsoget_payload_type()
.data_len – The size of the
data
if provided. This is only used if thedata_type
is also given.
- Returns
Note
Note that images with chunk payload types are saved with only the image data preserved. Remember to specify the non-chunk equivalent payload type when creating images with these chunk payload types. For example, images need to be created with PAYLOAD_TYPE_IMAGE payload type if the original image had PAYLOAD_TYPE_EXTENDED_CHUNK payload type.
- deep_copy_from(self, Image source)
Copies the given image into this image.
After this operation, this and the source image contents and member variables will be the same. However, the images will not share a buffer. The source image’s buffer will not be
release()
so you must still release it if it’s a camera acquired image.
- static deep_copy_image(Image image) Image
Creates and returns an image by copying all the data from the other image so they don’t share buffers.
- get_bits_per_pixel(self)
Gets the number of bits used per pixel in the image.
- get_buffer_size(self)
Gets the size of the buffer associated with the image in bytes.
For user created images, this function returns the size of the user provided data if the data size was provided when creating or setting the image. If the data size was not provided, the buffer size is calculated based on the image dimensions and pixel format.
The buffer size may be large than the actual image size as returned by
get_image_data_size()
orget_valid_payload_size()
.
- get_chunk_data(self)
Returns a
ImageChunkData
of the image.Warning
The
ImageChunkData
is only valid untilrelease()
is called.
- get_color_processing_algo(self) unicode
Gets the color processing algorithm of this image.
- Returns
The name of the color processing algorithm used as listed in
color_processing_algo_names
.
- get_completed(self)
Returns whether this image was incomplete.
An image is marked as incomplete if the transport layer received less data then it requested.
- static get_compression_threads() int
Gets the default number of threads used for image decompression during
convert()
.
- get_crc(self)
Returns whether the computed checksum matches with chunk data’s ImageCRC.
- get_data_max(self)
Get the value which no image data will exceed.
- get_data_min(self)
Get the value which no image data will be less than.
- static get_default_color_processing_algo() str
Gets the default color processing algorithm of all images (if not otherwise set).
- Returns
The name of the color processing algorithm used by default as listed in
color_processing_algo_names
.
- get_frame_id(self)
Gets the image’s acquisition frame ID.
- get_frame_timestamp(self)
Gets the time stamp for the image in nanoseconds.
- get_height(self)
Gets the height of the image in pixels.
- get_image_data(self)
Gets and copies the image data and returns it as a bytearray.
This does not include any additional payload data included with the image. For compressed images, the full image may be larger once decompressed.
See also
copy_image_data()
andget_image_data_memoryview()
.For example:
>>> image = Image.create_image(640, 480, 0, 0, 'Mono16') >>> data = image.get_image_data() >>> type(data) <class 'bytearray'> >>> len(view) 614400
TODO: Understand the format of the data.
- get_image_data_memoryview(self)
Gets the image data as a memory view of the underlying data without copying. This is much more efficient than
get_image_data()
, but more dangerous.This does not include any additional payload data included with the image. For compressed images, the full image may be larger once decompressed.
Warning
You MUST ensure that this
Image
instance does not go out of memory and the image and buffers are not released as long as the returned memory view of the array is in use. Otherwise, when the original data will become invalid, usage of the memory view will crash python.For example:
>>> image = Image.create_image(640, 480, 0, 0, 'Mono16') >>> view = image.get_image_data_memoryview() >>> view <rotpy.image.array object at 0x0000021CE7420B20> >>> # memview is the only attribute of cython arrays >>> view.memview <MemoryView of 'array' object> >>> view.memview.size 614400
- get_image_data_size(self)
Gets the size of the image and just the image - not including any additional payloads with the image.
For chunk images, only the size of chunk image portion is reported here. The entire chunk data payload including the image and full payload can be gotten by
get_valid_payload_size()
. For compressed images, this value may be different than the image size once decompressed.
- get_image_id(self)
Gets a unique ID for this image.
Each image in a steam will have a unique ID to help identify it.
- get_in_use(self)
Returns whether the image is still in use by the stream.
- get_is_compressed(self)
Returns whether this image is compressed.
- get_layout_id(self)
Returns the id of the chunk data layout.
- get_num_channels(self)
Gets the number of channels (depth) used in the image.
Returns 0 if the number of channels for the given pixel format is unknown.
- get_offset_x(self)
Gets the ROI x offset in pixels for this image.
- get_offset_y(self)
Gets the ROI y offset in pixels for this image.
- get_padding_x(self)
Gets the x padding in bytes for this image.
This is the number of bytes at the end of each line to facilitate alignment in buffers.
- get_padding_y(self)
Gets the y padding in bytes for this image. This is the number of bytes at the end of each image to facilitate alignment in buffers.
- get_payload_type(self)
Gets the payload type that was transmitted.
This is a device types specific value that identifies how the image was transmitted.
This returns the payload type name string from
payload_type_names
.
- get_pix_fmt(self)
Gets the image’s pixel format.
This returns the pixel format name string from
PixelFormat_names
.
- get_pix_fmt_int_type(self)
Gets the image’s integer type used in the pixel format of this image.
This returns the name string from
pix_fmt_int_names
.
- get_pix_fmt_sfnc(self)
Returns a string value that represents this image’s pixel format.
The string is a valid SFNC name that maps to the underlying TL specific pixel format. This is the most generic way to identify the pixel format of the image.
- get_status(self)
Returns data integrity status of the image when it was returned from
get_next_image()
.This returns the name string from
img_status_names
.
- static get_status_description(unicode status)
Returns a string describing the meaning of the status string from
get_status()
.- Parameters
status – A status string from
img_status_names
.
- get_stride(self)
Gets the stride of the image in bytes.
The stride of an image is how many bytes are in each row.
- get_tl_payload_type(self)
Gets the GenTL specific payload type that was transmitted.
This is a Transport Layer specific value that identifies how the image was transmitted.
This returns the payload type name string from
payload_type_names
.
- get_tl_pix_fmt(self)
Gets the pixel format of the image.
This is a Transport Layer specific pixel format that identifies how the pixels in the image should be interpreted. To understand how to interpret this value it is necessary to know what the transport layer namespace is. This can be retrieved through
get_tl_pix_fmt_namespace()
.
- get_tl_pix_fmt_namespace(self)
Gets the image’s underlying transport layer namespace in which this image’s TL specific pixel format resides.
This returns the name string from
pix_fmt_namespace_names
.
- get_valid_payload_size(self)
Gets the size of valid data in the image payload.
This is the actual amount of data read from the device, including any additional private data. A user created image has a payload size of zero. The value returned here can be equal to the value returned by
get_image_data_size()
if image data is the only payload. Note thatget_buffer_size()
returns the total size of bytes allocated for the image and could be equal to or greater than the size returned by this function.
- get_width(self)
Gets the width of the image in pixels.
- has_crc(self)
Returns whether the image contains ImageCRC checksum from the chunk data.
- release(self)
Release the image and its data for images gotten with
get_next_image()
.If the image has been returned from the camera buffer, our hold over it is released and the camera can reuse the buffer. If we created the image manually it doesn’t do anything.
release()
must be called to release the image if it was returned by the camera. Otherwise, the camera can not re-use the buffer. For manually created images, this is not necessary as it happens automatically when the image is deleted.Warning
Once called, all image operations are invalid and image methods should not be called.
- reset_image(self, int width, int height, int x_offset, int y_offset, unicode pix_fmt, data=None, unicode data_type=u'', size_t data_len=0)
Sets new dimensions of the image object and allocates memory if needed.
- Parameters
width – The image width.
height – The image height.
x_offset – The x-offset of the start of the image.
y_offset – The y-offset of the start of the image.
pix_fmt – The pixel format name string from
PixelFormat_names
.data – An optional bytes buffer or array containing the data to initialize the image with. If None, memory is automatically allocated.
data_type – The optional payload type of the data as named in
payload_type_names
(such as compressed). See alsoget_payload_type()
. See alsocreate_image()
.data_len – The size of the
data
if provided. This is only used if thedata_type
is also given.
- save_bmp(self, unicode filename, bool indexed_color_8bit=False)
Saves the image to a bmp file.
- Parameters
filename – The filename.
indexed_color_8bit – Whether to save as a 8-bit color index bmp (default False).
- save_file(self, unicode filename, unicode file_format=u'from_file_ext')
Saves the image to a file, depending on the format specified.
- Parameters
filename – The filename.
file_format – The file format to save - it’s a string from the options
img_file_fmt_names
. By default it guesses from the extension.
- save_jpeg(self, unicode filename, bool progressive=False, unsigned int quality=75)
Saves the image to a JPEG file.
- Parameters
filename – The filename.
progressive – Whether to save as a progressive JPEG (default False).
quality – JPEG image quality in range (0-100) (default 75). 100 - Superb quality, 75 - Good quality, 50 - Normal quality, 10 - Poor quality.
- save_jpeg2(self, unicode filename, unsigned int quality=16)
Saves the image to a JPEG2000 file.
- Parameters
filename – The filename.
quality – JPEG image quality in range (1-512) (default 16).
- save_pgm(self, unicode filename, bool binary=True)
Saves the image to a pgm file.
- Parameters
filename – The filename.
binary – Whether to save as a binary file (default True).
- save_png(self, unicode filename, bool interlaced=False, unsigned int compression=6)
Saves the image to a png file.
- Parameters
filename – The filename.
interlaced – Whether to save interlaced (default False).
compression – The compression level (default 6) (0-9). 0 is no compression, 9 is best compression.
- save_ppm(self, unicode filename, bool binary=True)
Saves the image to a ppm file.
- Parameters
filename – The filename.
binary – Whether to save as a binary file (default True).
- save_tiff(self, unicode filename, unicode compression=u'lzw')
Saves the image to a tiff file.
- Parameters
filename – The filename.
compression – The compression used to save the image (default lzw). It’s a string from the options
compression_names
.
- static set_compression_threads(unsigned int num)
Sets the default number of threads used for image decompression during
convert()
.The number of threads used is defaulted to be equal to one less than the number of concurrent threads supported by the system.
- Parameters
num – Number of parallel image decompression threads set to run.
- static set_default_color_processing_algo(unicode name)
Sets the default color processing algorithm of all images (if not otherwise set).
- Parameters
name – The name of the color processing algorithm used by default as listed in
color_processing_algo_names
.
- class ImageChunkData
Bases:
object
Represents some metadata about the raw
Image
.Warning
Do not create a
ImageChunkData
manually, rather get an instance from e.g.Image.get_chunk_data()
.Methods:
Returns the black level used to capture the image.
Returns the compression mode of the last image payload.
Returns the compression ratio of the last image payload.
Returns the value of the selected Chunk counter at the time of the FrameStart event.
Returns the CRC of the image payload.
Returns a dict with all the chunk data labeled with a visibility of
default
.Returns the counter's value of the selected Encoder at the time of the FrameStart in area scan mode or the counter's value at the time of the LineStart selected by ChunkScanLineSelector in LineScan mode.
Returns a dict with all the chunk data labeled with a visibility of
expert
.Returns the status of all the I/O lines at the end of exposure event.
Returns the exposure time used to capture the image.
Returns the image frame ID.
Returns the gain used to capture the image.
Returns the height of the image included in the payload.
Returns the image payload.
Returns the chunk data inference confidence percentage.
Returns a
ChunkDataInference
that represents the inferred labeling of various areas of the image chunk.Returns the frame ID associated with the most recent inference result.
Returns the chunk data inference result.
Returns the LinePitch of the image included in the payload.
Returns the status of all the I/O lines at the time of the FrameStart internal event.
Returns the Offset X of the image included in the payload.
Returns the Offset Y of the image included in the payload.
Selects the part to access in chunk data in a multipart transmission.
Returns the maximum value of dynamic range of the image included in the payload.
Returns the minimum value of dynamic range of the image included in the payload.
Returns the Maximum Axis value for the selected coordinate axis of the image included in the payload.
Returns the Minimum Axis value for the selected coordinate axis of the image included in the payload.
Returns the Offset for the selected coordinate axis of the image included in the payload.
Reads the value of a position or pose coordinate for the anchor or transformed coordinate systems relative to the reference point.
Returns the Scale for the selected coordinate axis of the image included in the payload.
Returns the Invalid Data Value used for the image included in the payload.
Returns the transform value.
Index for vector representation of one chunk value per line in an image.
Returns the index of the active set of the running sequencer included in the payload.
Returns the length of the received serial data that was included in the payload.
Returns identifier of the stream channel used to carry the block.
Returns the value of the selected Timer at the time of the FrameStart internal event.
Returns the Timestamp of the image.
Returns the last Timestamp latched with the TimestampLatch command.
Returns the unique identifier of the transfer block used to transport the payload.
Returns the current number of blocks in the transfer queue.
Returns the width of the image included in the payload.
- get_black_level(self)
Returns the black level used to capture the image.
Visibility:
default
.
- get_compression_mode(self)
Returns the compression mode of the last image payload.
Visibility:
default
.
- get_compression_ratio(self)
Returns the compression ratio of the last image payload.
Visibility:
default
.
- get_counter_value(self)
Returns the value of the selected Chunk counter at the time of the FrameStart event.
Visibility:
Expert
.
- get_crc(self)
Returns the CRC of the image payload.
Visibility:
default
.
- get_data(self)
Returns a dict with all the chunk data labeled with a visibility of
default
.
- get_encoder_value(self)
Returns the counter’s value of the selected Encoder at the time of the FrameStart in area scan mode or the counter’s value at the time of the LineStart selected by ChunkScanLineSelector in LineScan mode.
Visibility:
Expert
.
- get_expert_data(self)
Returns a dict with all the chunk data labeled with a visibility of
expert
.
- get_exposure_end_line_status_all(self)
Returns the status of all the I/O lines at the end of exposure event.
Visibility:
default
.
- get_exposure_time(self)
Returns the exposure time used to capture the image.
Visibility:
default
.
- get_frame_id(self)
Returns the image frame ID.
Visibility:
default
.
- get_gain(self)
Returns the gain used to capture the image.
Visibility:
default
.
- get_height(self)
Returns the height of the image included in the payload.
Visibility:
default
.
- get_image(self)
Returns the image payload.
Visibility:
default
.
- get_inference_confidence(self)
Returns the chunk data inference confidence percentage.
Visibility:
Expert
.
- get_inference_data(self)
Returns a
ChunkDataInference
that represents the inferred labeling of various areas of the image chunk.
- get_inference_frame_id(self)
Returns the frame ID associated with the most recent inference result.
Visibility:
Expert
.
- get_inference_result(self)
Returns the chunk data inference result.
Visibility:
Expert
.
- get_line_pitch(self)
Returns the LinePitch of the image included in the payload.
Visibility:
Expert
.
- get_line_status_all(self)
Returns the status of all the I/O lines at the time of the FrameStart internal event.
Visibility:
Expert
.
- get_offset_x(self)
Returns the Offset X of the image included in the payload.
Visibility:
default
.
- get_offset_y(self)
Returns the Offset Y of the image included in the payload.
Visibility:
default
.
- get_part_selector(self)
Selects the part to access in chunk data in a multipart transmission.
Visibility:
Expert
.
- get_pixel_dynamic_range_max(self)
Returns the maximum value of dynamic range of the image included in the payload.
Visibility:
Expert
.
- get_pixel_dynamic_range_min(self)
Returns the minimum value of dynamic range of the image included in the payload.
Visibility:
Expert
.
- get_scan3d_axis_max(self)
Returns the Maximum Axis value for the selected coordinate axis of the image included in the payload.
Visibility:
Expert
.
- get_scan3d_axis_min(self)
Returns the Minimum Axis value for the selected coordinate axis of the image included in the payload.
Visibility:
Expert
.
- get_scan3d_coordinate_offset(self)
Returns the Offset for the selected coordinate axis of the image included in the payload.
Visibility:
Expert
.
- get_scan3d_coordinate_reference_value(self)
Reads the value of a position or pose coordinate for the anchor or transformed coordinate systems relative to the reference point.
Visibility:
Expert
.
- get_scan3d_coordinate_scale(self)
Returns the Scale for the selected coordinate axis of the image included in the payload.
Visibility:
Expert
.
- get_scan3d_invalid_data_value(self)
Returns the Invalid Data Value used for the image included in the payload.
Visibility:
Expert
.
- get_scan3d_transform_value(self)
Returns the transform value.
Visibility:
Expert
.
- get_scan_line_selector(self)
Index for vector representation of one chunk value per line in an image.
Visibility:
Expert
.
- get_sequencer_set_active(self)
Returns the index of the active set of the running sequencer included in the payload.
Visibility:
default
.
- get_serial_data_length(self)
Returns the length of the received serial data that was included in the payload.
Visibility:
default
.
- get_stream_channel_id(self)
Returns identifier of the stream channel used to carry the block.
Visibility:
Expert
.
- get_timer_value(self)
Returns the value of the selected Timer at the time of the FrameStart internal event.
Visibility:
Expert
.
- get_timestamp(self)
Returns the Timestamp of the image.
Visibility:
default
.
- get_timestamp_latch_value(self)
Returns the last Timestamp latched with the TimestampLatch command.
Visibility:
Expert
.
- get_transfer_block_id(self)
Returns the unique identifier of the transfer block used to transport the payload.
Visibility:
Expert
.
- get_transfer_queue_current_block_count(self)
Returns the current number of blocks in the transfer queue.
Visibility:
Expert
.
- get_width(self)
Returns the width of the image included in the payload.
Visibility:
default
.
- class ChunkDataInference
Bases:
object
Represents object location inference data from a
Image
.Some cameras support automatically detecting objects using pre-trained machine learning algorithms,
ChunkDataInference
represents the inferred object detection.Warning
Do not create a
ChunkDataInference
manually, rather get an instance from e.g.ImageChunkData.get_inference_data()
.Methods:
Returns the bounding box at the zero-based
index
that is less thanget_num_boxes()
.Returns the number of bytes allocated for one bounding box.
Returns a list of all the inferred boxes.
Returns the number of bounding boxes.
Returns the bounding box format version number.
- get_box(self, uint16_t index)
Returns the bounding box at the zero-based
index
that is less thanget_num_boxes()
.The total number of boxes is
get_num_boxes()
.- Parameters
index – The box index to get.
- Returns
Returns a 4-tuple of
(class, confidence, type, value)
, whereclass
is the class ID of the box,confidence
is our confidence in it, type is a string indicating the box type and it’s one of"rect"
,"rotated_rect"
, or"circle"
.value
is dependant on the type.If type is
"rect"
,value
is a 4-tuple of(top_left_x, top_left_y, bottom_right_x, bottom_right_y)
. If type is"rotated_rect"
,value
is a 5-tuple of(top_left_x, top_left_y, bottom_right_x, bottom_right_y, rotation_angle)
. If type is"circle"
,value
is a 3-tuple of(center_x, center_y, radius)
.
- get_box_size(self)
Returns the number of bytes allocated for one bounding box.
- get_boxes(self)
Returns a list of all the inferred boxes.
It returns a list of tuples, where each tuple is in the format as returned by
get_box()
.
- get_num_boxes(self)
Returns the number of bounding boxes.
- get_version(self)
Returns the bounding box format version number.