跳转到内容
STAGING SERVER
DEVELOPMENT SERVER

Python Programmer's Guide#

This section provides information specific to Basler Stereo ace cameras. It doesn't aim to give a comprehensive overview of the official Python language binding for Basler pylon.

The official Python language binding for Basler pylon is the pypylon project. pypylon is an open-source project hosted on GitHub. You need version 4.0 or above in order to use Basler Stereo ace cameras.

If you are new to pypylon, Basler recommends making yourself familiar with the pypylon API first by reading the pypylon documentation.

Prerequisites#

安装#

Installing pypylon#

To use Stereo mini cameras with Python, install the pypylon package:

pip install pypylon

This package provides Python bindings for the pylon SDK.

For the provided sample set, install the dependencies in each sample folder:

  • stereo mini/python/SimpleGrab/requirements.txt
  • stereo mini/python/ShowPointCloud/requirements.txt

使用入门#

Running the Samples#

The pylon Supplementary Package for Stereo mini includes some Python programming samples that illustrate how to access a Stereo mini camera using Python and pypylon.

The Python samples are located in the C:\Program Files\Basler\pylon\Development\Samples\Stereo_mini\Python folder.

The Python samples are located in the /opt/pylon/share/pylon/Samples/Stereo_mini/Python folder.

The Python samples are located in the /opt/pylon/share/pylon/Samples/Stereo_mini/Python folder.

信息

Before building the samples, copy the folder containing the samples to a location of your choice where you have write permissions.

To run a Python sample, navigate to the folder containing the sample and execute it using Python. Example:

python SimpleGrab.py

Check the Troubleshooting topic if you experience problems running the samples.

List of Samples#

  • SimpleGrab: Illustrates how to grab images from a Stereo mini camera and access color and depth data.
  • ShowPointCloud: Illustrates how to grab and visualize a point cloud from a Stereo mini camera using Open3D.

Refer to the sample code in the Python samples directory for more details.

How to Use pypylon with Stereo mini Cameras#

Importing the Required Modules#

from pypylon import pylon

import numpy as np

Connecting to a Camera#

The following example demonstrates how to open the first available Stereo mini camera using pypylon:

# Create Stereo mini filter to avoid opening a non-Stereo-mini device
di = pylon.DeviceInfo()
di.SetDeviceClass("BaslerGTC/Basler/TLModel_keep")

camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice(di))

print(f"Using camera: {camera.GetDeviceInfo().GetFriendlyName()}")

camera.Open()

To open a specific Stereo mini camera, set the serial number or user-defined name before creating the camera:

# Open a specific Stereo mini camera by serial number
di.SetSerialNumber("12345678")

# Open a specific Stereo mini camera by user-defined name
di.SetUserDefinedName("MyStereoMini")

Accessing Camera Parameters#

You can access camera parameters via the camera object, for example:

# Example parameter access
camera.ExposureTime.Value = 5000  # microseconds
camera.Gain.Value = 5.0

print(f"ExposureTime: {camera.ExposureTime.Value}")
print(f"Gain: {camera.Gain.Value}")

Grabbing Images#

The following example demonstrates how to grab images from a Stereo mini camera:

camera.StartGrabbing()

grab_result = camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)

if grab_result.GrabSucceeded():
    data_container = grab_result.GetDataContainer()
    print(f"Components: {data_container.DataComponentCount}")

grab_result.Release()

Accessing Depth Data#

Stereo mini cameras provide both intensity and range components. The samples use:

  • Coord3D_C16 for 16-bit range values
  • Coord3D_ABC32f for direct XYZ point data
# Configure range format
camera.ComponentSelector.Value = "Range"
camera.PixelFormat.Value = "Coord3D_C16"