IDS peak ICV v1.1.0
Loading...
Searching...
No Matches
Getting started with the ICV Python interface

This tutorial introduces the basics of acquiring and processing images using the ICV Python interface.

Prerequisites

Before retrieving or processing images, ensure the following requirements are met:

  1. Camera connection

    Confirm that a IDS camera is properly connected to your system and capable of acquiring images.

  2. Open DataStream

    To receive image data, you must open a DataStream using the IDS peak genericAPI. This step is essential because the raw image buffers come from the IDS peak genericAPI, not the ICV interface. For details on opening a DataStream, see the IDS peak genericAPI documentation.

  3. Python interface

    Make sure the ICV Python interface is installed on your system.

Import required modules

Import the following modules, as they are required for the example below:

from ids_peak_icv.pipeline import DefaultPipeline
from ids_peak_common import PixelFormat
  • DefaultPipeline Provides the image processing pipeline that converts raw acquisition data into usable images.
  • PixelFormat An enumeration of available pixel formats. used to specify the desired format of the output image.

Note: Pixel formats are a shared concept across the IDS Peak SDK.
They are used by IDS peak genericAPI, IDS peak ICV, and other components. To keep them consistent and reusable, they are defined in the ids_peak_common module.

Acquiring an Image

The IDS peak ICV Python interface uses an image pipeline to process raw acquisition data into usable images. This pipeline handles tasks such as image format conversion and preprocessing, ensuring the resulting image is ready for further analysis.

The example below demonstrates how to retrieve an image using this pipeline, assuming that a DataStream object is available:

# Initialize pipeline with default settings
pipeline = DefaultPipeline()
# Set the target format to monochrome
pipeline.output_pixel_format = PixelFormat.MONO_8
# Get a buffer from IDS peak genericAPI
buffer = data_stream.WaitForFinishedBuffer(ids_peak.Timeout(5000))
# Convert the buffer to an ImageView
image_view = buffer.ToImageView()
# Process the ImageView to obtain a ICV image
image = pipeline.process(image_view)

Note: By default, the pipeline outputs a color image (RGB), also for monochrome cameras. Set the output format to PixelFormat.MONO_8 for monochrome cameras as well.

Basic image processing

As an initial processing step, apply a threshold to isolate bright pixels within the acquired image:

# Define a threshold for pixel gray values between 128 and 255
threshold = Threshold(Interval(128, 255))
# Process the image to extract the bright pixel region
region = threshold.process(image)

This operation produces a region representing all pixels within the specified gray value range, which can be used for further analysis.

Analyzing the Region

You can analyze the extracted region by measuring its area:

area = region.area
print(f"The area of the extracted region is {area} pixels")