Grab#

Grab.py#
from itala import itala

ACQUIRE_COUNT = 50


def grab():
    system = itala.create_system()
    devices_info = system.enumerate_devices(500)
    if(len(devices_info) == 0):
        print("No devices found. Example canceled.")
        exit(1)
    if(devices_info[0].access_status != itala.DeviceAccessStatus_AvailableReadWrite):
        print("Target device is unaccessible in RW mode. Example cancelled.")
        exit(1)
    device = system.create_device(devices_info[0])
    print("First device initialized.")

    # Start a default continuous acquisition. Internally, the runtime allocates a
    # queue of 16 image buffers thus a maximum of 16 images can be grabbed simultaneously
    # without being released. An additional overload function allows to set the
    # buffer and frame count.
    device.start_acquisition()
    print("Acquisition started.")

    # Perform a continuous acquisition by looping ACQUIRE_COUNT times and
    # and grab a new image at every loop.
    for i in range(ACQUIRE_COUNT):
        # Grab the first available image. If the specified
        # 1000ms timeout expires, a TimeoutException occurs. Don't forget to
        # dispose the image when it's no longer needed.
        image = device.get_next_image(1000)

        # Check if the image data is incomplete. This may happen due to packets
        # lost during transmission. Packets could get lost for many of reasons
        # resulting from an incorrect network setup, bad camera configuration,
        # poor hardware quality or inadequate conditions of the environment.
        if(image.is_incomplete):
            print("Incomplete image.")
            print(f"\tBytes filled: {image.bytes_filled}/{image.payload_size}")
        else:
            print("Image grabbed.")

        print(f"\tFrameID: {image.frame_id}")
        print(f"\tTimestamp: {image.timestamp}")

        # DO SOMETHING WITH THE IMAGE
        
        # When the image is no longer required (e.g. when the current loop is over)
        # it MUST be disposed by calling the dedicated function. When an image is
        # disposed, its memory is released and it can be reused for a new grab.
        image.dispose()

    device.stop_acquisition()
    print("Acquisition stopped.")

    device.dispose()
    print("Device instance disposed.")

    system.dispose()
    print("System instance disposed.")


if __name__ == "__main__":
    try:
        grab()
    except Exception as e:
        print(str(e))
        exit(1)
    exit(0)