Skip to main content

ids_peak - A library for device communication

Project description

ids_peak provides python bindings for the IDS peak genericAPI. It exposes all the functionality of the peak genericAPI and requires at least the drivers and GenICam transport layers to be installed, which are included in the IDS peak SDK.

Benefit from many Python advantages, for example the interactive programming of your IDS camera. Write and test small code snippets without the complex setup of a programming IDE including a toolchain. This package is ideal for prototyping IDS camera applications for all supported peak genericAPI platforms (Windows, Linux, Linux Embedded).

Installation

$ pip install ids_peak

Quickstart

This example shows how to open a device, start image acquisition and how to convert a buffer to an ids_peak_ipl.Image.

NOTE: For the sake of simplicity, most of the error checking has been omitted in this example.

from ids_peak import ids_peak
from ids_peak import ids_peak_ipl_extension


def main():
    # Initialize library
    ids_peak.Library.Initialize()

    # Create a DeviceManager object
    device_manager = ids_peak.DeviceManager.Instance()

    try:
        # The returned callback object needs to be stored in a variable and
        # needs to live as long as the class that would call it,
        # so as long as the device manager in this case
        # If the callback gets garbage collected it deregisters itself
        device_found_callback = device_manager.DeviceFoundCallback(
            lambda found_device: print(
                "Found-Device-Callback: Key={}".format(
                    found_device.Key()), end="\n\n"))
        device_found_callback_handle = device_manager.RegisterDeviceFoundCallback(
            device_found_callback)

        # Update the DeviceManager
        device_manager.Update()
        # The callback can also be unregistered explicitly using the returned
        # handle
        device_manager.UnregisterDeviceFoundCallback(
            device_found_callback_handle)

        # Exit program if no device was found
        if device_manager.Devices().empty():
            print("No device found. Exiting Program.")
            return -1

        # Open the first device
        device = device_manager.Devices()[0].OpenDevice(
            ids_peak.DeviceAccessType_Control)

        # Nodemap for accessing GenICam nodes
        remote_nodemap = device.RemoteDevice().NodeMaps()[0]

        # Load default camera settings
        remote_nodemap.FindNode("UserSetSelector").SetCurrentEntry("Default")
        remote_nodemap.FindNode("UserSetLoad").Execute()
        remote_nodemap.FindNode("UserSetLoad").WaitUntilDone()

        # Open first data stream
        data_stream = device.DataStreams()[0].OpenDataStream()
        # Buffer size
        payload_size = remote_nodemap.FindNode("PayloadSize").Value()

        # Minimum number of required buffers
        buffer_count_max = data_stream.NumBuffersAnnouncedMinRequired()

        # Allocate buffers and add them to the pool
        for buffer_count in range(buffer_count_max):
            # Let the TL allocate the buffers
            buffer = data_stream.AllocAndAnnounceBuffer(payload_size)
            # Put the buffer in the pool
            data_stream.QueueBuffer(buffer)

        # Lock writeable nodes during acquisition
        remote_nodemap.FindNode("TLParamsLocked").SetValue(1)

        print("Starting acquisition...")
        data_stream.StartAcquisition()
        remote_nodemap.FindNode("AcquisitionStart").Execute()
        remote_nodemap.FindNode("AcquisitionStart").WaitUntilDone()

        print("Getting 100 images...")
        # Process 100 images
        for _ in range(100):
            try:
                # Wait for finished/filled buffer event
                buffer = data_stream.WaitForFinishedBuffer(1000)
                img = ids_peak_ipl_extension.BufferToImage(buffer)

                # Do something with `img` here ...

                # Put the buffer back in the pool, so it can be filled again
                # NOTE: If you want to use `img` beyond this point, you have
                #       to make a copy, since `img` still uses the underlying
                #       buffer's memory.
                data_stream.QueueBuffer(buffer)
            except Exception as e:
                print(f"Exception: {e}")

        print("Stopping acquisition...")
        remote_nodemap.FindNode("AcquisitionStop").Execute()
        remote_nodemap.FindNode("AcquisitionStop").WaitUntilDone()

        data_stream.StopAcquisition(ids_peak.AcquisitionStopMode_Default)

        # In case another thread is waiting on WaitForFinishedBuffer
        # you can interrupt it using:
        # data_stream.KillWait()

        # Remove buffers from any associated queue
        data_stream.Flush(ids_peak.DataStreamFlushMode_DiscardAll)

        for buffer in data_stream.AnnouncedBuffers():
            # Remove buffer from the transport layer
            data_stream.RevokeBuffer(buffer)

        # Unlock writeable nodes again
        remote_nodemap.FindNode("TLParamsLocked").SetValue(0)

    except Exception as e:
        print("EXCEPTION: " + str(e))
        return -2

    finally:
        ids_peak.Library.Close()


if __name__ == '__main__':
    main()

Documentation

Documentation is available here

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

ids_peak-1.9.0.0.2-cp37-abi3-win_amd64.whl (3.7 MB view details)

Uploaded CPython 3.7+ Windows x86-64

ids_peak-1.9.0.0.2-cp37-abi3-win32.whl (2.7 MB view details)

Uploaded CPython 3.7+ Windows x86

ids_peak-1.9.0.0.2-cp37-abi3-manylinux_2_27_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.27+ x86-64

ids_peak-1.9.0.0.2-cp37-abi3-manylinux_2_27_i686.whl (3.7 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.27+ i686

ids_peak-1.9.0.0.2-cp37-abi3-manylinux_2_27_armv7l.whl (3.5 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.27+ ARMv7l

ids_peak-1.9.0.0.2-cp37-abi3-manylinux_2_27_aarch64.whl (3.7 MB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.27+ ARM64

File details

Details for the file ids_peak-1.9.0.0.2-cp37-abi3-win_amd64.whl.

File metadata

File hashes

Hashes for ids_peak-1.9.0.0.2-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 1eff8bf984156829714373da1036cb0263605cc5f5f680e97f783506755e53b6
MD5 18f911b0d67b53d1764c5dfecc96ec8b
BLAKE2b-256 287259fca347b7db2edafed41305752adacfe15a5ca0aaaeb8a77b48de291c1b

See more details on using hashes here.

File details

Details for the file ids_peak-1.9.0.0.2-cp37-abi3-win32.whl.

File metadata

  • Download URL: ids_peak-1.9.0.0.2-cp37-abi3-win32.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: CPython 3.7+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for ids_peak-1.9.0.0.2-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 9ce79e598668e88b7fd189a29b4436d481c9441730dc14c00ff1e3ce1fd7dbc1
MD5 f273834fbe43157c29cb1e31d3ff5ae5
BLAKE2b-256 360f0865e5bc0341b1fdf22255a311b5b64c003b4c61e1f5c1e1fe84b126e11d

See more details on using hashes here.

File details

Details for the file ids_peak-1.9.0.0.2-cp37-abi3-manylinux_2_27_x86_64.whl.

File metadata

File hashes

Hashes for ids_peak-1.9.0.0.2-cp37-abi3-manylinux_2_27_x86_64.whl
Algorithm Hash digest
SHA256 7fcbed7154392e1921d1c84af1894d1220f9fa690c22a5df63a8d68226f19fd6
MD5 7792019bd7f15cdc30aa0e8c5b9ae3aa
BLAKE2b-256 bc05a2d448112f03a68ca6b7190ddbaaa516ea291fcd420c4df05f84b1f3b710

See more details on using hashes here.

File details

Details for the file ids_peak-1.9.0.0.2-cp37-abi3-manylinux_2_27_i686.whl.

File metadata

File hashes

Hashes for ids_peak-1.9.0.0.2-cp37-abi3-manylinux_2_27_i686.whl
Algorithm Hash digest
SHA256 b522ed7986ccf74e8317422a5aef72c28c5e218280098d248a0fe209e48f32bd
MD5 1439948a09688d5265d328e1d936fded
BLAKE2b-256 f26f0489b10dceb8808a92df1284e572ff6d8572c106f5bb56d06cba795dfd99

See more details on using hashes here.

File details

Details for the file ids_peak-1.9.0.0.2-cp37-abi3-manylinux_2_27_armv7l.whl.

File metadata

File hashes

Hashes for ids_peak-1.9.0.0.2-cp37-abi3-manylinux_2_27_armv7l.whl
Algorithm Hash digest
SHA256 458b969e33526b7aba2f9b824d78aa85e2983156a4b88b674ea2f8abb490917c
MD5 0ce4ef0641dcaa69d2a25e3d2b911fd6
BLAKE2b-256 3563a8e155388129922381b73fa9e4c95cf9c30c6819ac4041d906161f21d3f1

See more details on using hashes here.

File details

Details for the file ids_peak-1.9.0.0.2-cp37-abi3-manylinux_2_27_aarch64.whl.

File metadata

File hashes

Hashes for ids_peak-1.9.0.0.2-cp37-abi3-manylinux_2_27_aarch64.whl
Algorithm Hash digest
SHA256 34ef51a0b9fb1129014fa56e562883dd2c716673320e6d6abcb52afefda672ac
MD5 1a2b3868e9d94bcd985ff4cd1f08689e
BLAKE2b-256 129b1f36f11c8ab42534c4adf05f53f8630803a2b97596fa5e23a71aad93288e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page