ids_peak_afl - A library for auto features
Project description
ids_peak_afl provides python bindings for the IDS peak AFL. It exposes all the functionality of the peak AFL 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 AFL platforms (Windows, Linux, Linux Embedded).
Installation
$ pip install ids_peak_afl
Quickstart
This example shows how to open a device, start image acquisition
and use the ids_peak_afl package for triggering a host-sided
automatic adjustment of image brightness (requires version >=1.2
).
NOTE: For the sake of simplicity, most of the error checking has been omitted in this example.
from ids_peak import ids_peak, ids_peak_ipl_extension
from ids_peak_ipl import ids_peak_ipl
from ids_peak_afl import ids_peak_afl
class FinishedCallback(
ids_peak_afl.FinishedCallback):
def callback(self) -> None:
print("ControllerFinishedCallback!")
class ComponentExposureFinishedCallback(
ids_peak_afl.ComponentExposureFinishedCallback):
def callback(self) -> None:
print("ExposureFinishedCallback!")
class ComponentGainFinishedCallback(
ids_peak_afl.ComponentGainFinishedCallback):
def callback(self) -> None:
print("GainFinishedCallback!")
def main():
# Initialize library calls should be matched by a corresponding
# Exit or close call
ids_peak.Library.Initialize()
ids_peak_afl.Library.Init()
# Create a DeviceManager object
device_manager = ids_peak.DeviceManager.Instance()
try:
# Update the DeviceManager
device_manager.Update()
# 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)
print(f"Device: {device.SerialNumber()} -> {device.DisplayName()}")
# Nodemap for accessing GenICam nodes
remote_nodemap = device.RemoteDevice().NodeMaps()[0]
# Autofeature manager, which can have multiple controllers
manager = ids_peak_afl.Manager(remote_nodemap)
# Create autofocus controller
controller = manager.CreateController(
ids_peak_afl.PEAK_AFL_CONTROLLER_TYPE_BRIGHTNESS)
print(f"Controller Status: {controller.Status()}")
print(f"Controller Type: {controller.Type()}")
# Load default camera settings
remote_nodemap.FindNode("UserSetSelector").SetCurrentEntry("Default")
remote_nodemap.FindNode("UserSetLoad").Execute()
remote_nodemap.FindNode("UserSetLoad").WaitUntilDone()
# Auto brightness mode is split up in two components
# so you can't use the regular controller.SetMode etc.
# NOTE: mode is reset to off automatically after the operation finishes
# when using PEAK_AFL_CONTROLLER_AUTOMODE_ONCE
controller.BrightnessComponentSetMode(
ids_peak_afl.PEAK_AFL_CONTROLLER_BRIGHTNESS_COMPONENT_EXPOSURE,
ids_peak_afl.PEAK_AFL_CONTROLLER_AUTOMODE_ONCE,
)
controller.BrightnessComponentSetMode(
ids_peak_afl.PEAK_AFL_CONTROLLER_BRIGHTNESS_COMPONENT_GAIN,
ids_peak_afl.PEAK_AFL_CONTROLLER_AUTOMODE_ONCE,
)
# Register callbacks
# NOTE: these have to be assigned, otherwise they get destructed
# and the callback gets removed
finished = FinishedCallback(controller)
exposureFinished = ComponentExposureFinishedCallback(controller)
gainFinished = ComponentGainFinishedCallback(controller)
# 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)
# NOTE: If performance is a concern, then `ids_peak_ipl.ImageConverter`
# should be preferred.
mono_img = img.ConvertTo(ids_peak_ipl.PixelFormatName_Mono8)
# Put the buffer back in the pool, so it can be filled again
# NOTE: `ConvertTo` will make a copy, so it is fine to queue
# the buffer immediately after.
data_stream.QueueBuffer(buffer)
# Process the image in the autofeature manager, which will
# Apply all the actions of associated controllers
manager.Process(mono_img)
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)
# Last auto average for the controller working on a mono image
print(f"LastAutoAverage: {controller.GetLastAutoAverage()}")
except Exception as e:
print(f"EXCEPTION: {e}")
return -2
finally:
ids_peak_afl.Library.Exit()
ids_peak.Library.Close()
if __name__ == '__main__':
main()
Documentation
Documentation is available here
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for ids_peak_afl-1.5.0.0-cp37-abi3-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f01bf96181059a7974f83c1952efc2e6ebb2b018291d22d8ec9621f18a409a09 |
|
MD5 | 8533a3080de0b929ce2234bb2dc8a319 |
|
BLAKE2b-256 | 7a96e2bd8d3ce9e7c7dd835e95b01b9e6b222b0d1ca162d558664a71e94cb8dd |
Hashes for ids_peak_afl-1.5.0.0-cp37-abi3-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 781e43fb64e486589da896b09f18451a4261644e7b6781f33f36c5339f7751af |
|
MD5 | 6c822458fe4d02e81484ffaefa97aef3 |
|
BLAKE2b-256 | 54eef01675e14adf113f7770728e3695dcaaef5b19090b72a9204cb835dec55f |
Hashes for ids_peak_afl-1.5.0.0-cp37-abi3-manylinux_2_24_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4b8d2200380ef470571b1cf5a4ef4fcd844cc34a28a683004bc0256dd3375b3a |
|
MD5 | 9a005fba1c02b5a93bb1f8833547385e |
|
BLAKE2b-256 | 9b77f0ea0d77115c234ce8c66a0308cd1771c9143b35f4cd0f08d50e4780d4d2 |
Hashes for ids_peak_afl-1.5.0.0-cp37-abi3-manylinux_2_24_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f98028e8d45114bf322df28269d9e769a9f16f553eefb39f468961362f3b9ad0 |
|
MD5 | 115759a334671101ae01840ba4896a24 |
|
BLAKE2b-256 | 4ac9c48b89fdf6b62e572bf9636f5b72357a76a924d9477476f01b5a437eec83 |
Hashes for ids_peak_afl-1.5.0.0-cp37-abi3-manylinux_2_24_armv7l.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f4e7b4a96f28964a54e2f9a37d50f6c8e57bf6e667cd267485ad959a9516012a |
|
MD5 | 44ee493dca2fc62e0e7c56c5dfef7d6f |
|
BLAKE2b-256 | dd40c13c3ac87643eaee323a937d0e33e3755efb1f8cc00a9987442532697a8f |
Hashes for ids_peak_afl-1.5.0.0-cp37-abi3-manylinux_2_24_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 38b76b0732e947608d0e4f9137a54c413390cff204930fa6124ec9dfb75c4306 |
|
MD5 | 8f9272b12f26d42f5de50d043880e13e |
|
BLAKE2b-256 | 6109b8b3d0edaf51153142774b6e010234ef0633444a07aec0f2723985c5dbc5 |