コンテンツにスキップ
ステージングサーバー
開発サーバー

C++ プログラマーズガイド#

このセクションでは、Basler Stereo ace カメラ固有の情報を提供します。pylon C++ API の包括的な概要を網羅することを目的としたものではありません。

pylon を初めて使用する場合は、まず pylon C++ Programmer's Guide のGetting Startedセクションを読んで、pylon C++ API に慣れておくことを Basler は推奨しています。

C++ プログラミングサンプル#

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

The C++ samples are located in the /opt/pylon/share/pylon/Samples/Stereo_ace/C++/ folder.

The C++ samples are located in the /opt/pylon/share/pylon/Samples/Stereo_ace/C++/ folder.

サンプル構築の前提条件#

  • pylon 26.06 以降
  • Visual Studio 2019 or above
  • CMake 3.3 or above
  • CMake 3.3 or above

サンプルのビルド#

  1. Copy the Development\Samples\Stereo_ace\C++ folder to a location where you have write permissions.
  2. Launch Microsoft Visual Studio.
  3. Click the Open a local folder button, navigate to the Samples\Stereo_ace\C++ folder, and press the Select button.
    Wait until Visual Studio has finished generating the CMake cache. Once the cache generation has succeeded, the samples can be built and executed.

Open a command shell and enter the following commands:

mkdir -p $HOME/Stereo_ace_samples
cp -r /opt/pylon/share/pylon/Samples/Stereo_ace/C++ $HOME/Stereo_ace_samples
cd $HOME/Stereo_ace_samples
mkdir build
cd build
cmake ..
cmake --build .

Open a command shell and enter the following commands:

mkdir -p $HOME/Stereo_ace_samples
cp -r /opt/pylon/share/pylon/Samples/Stereo_ace/C++ $HOME/Stereo_ace_samples
cd $HOME/Stereo_ace_samples
mkdir build
cd build
cmake ..
cmake --build .

OpenCV または PCL が見つからない場合、CMake は不足しているライブラリを必要とするサンプルのみをスキップします。他のサンプルは引き続きビルドできます。

サンプルのビルドや実行で問題が発生した場合は、Troubleshootingトピックを確認してください。

OpenCV ライブラリのインストール#

You can download OpenCV here: https://github.com/opencv/opencv/releases

Make sure that you download a version of the OpenCV library that is compatible with the Visual Studio version you are going to use. If there is no suitable prebuilt version available, you have to build OpenCV from sources using the Visual Studio version you want to use for building your application.

If CMake fails to find OpenCV, set the OpenCV_DIR variable to the folder containing the OpenCVConfig.cmake file.

Examples

  1. Open the CMake Settings dialog (Project -> CMakeSettings for "Stereo ace samples")
  2. Enter the following command in the CMake command arguments field:
    -DOpenCV_DIR="C:\Program Files\OpenCV\build\x64\vc16\lib"
  3. Press Ctrl+S to save the changes.

Before you can access the OpenCV_DIR in the CMake GUI, make sure that the Grouped check box is deselected in the CMake GUI.

Enter the following command to use CMake from the command line:

cmake -DOpenCV_DIR="C:\Program Files\OpenCV\build\x64\vc16\lib" ..

Adding OpenCV to PATH Environment Variable#

You have to add the OpenCV bin directory to the PATH environment variable.

  1. Press the Win key.
  2. Type "environment".
  3. Click Edit environment variables for your account.
  4. In the User variables area, select Path.
  5. Click the Edit button.
  6. Click New.
  7. Enter the path of your OpenCV installation, e.g.:
    C:\Program Files\OpenCV\build\x64\vc16\bin
  8. Click OK.

If CMake fails to find the OpenCV library, you either have to install the libopencv development package or to build the OpenCV library from sources.

On Ubuntu systems, the libopencv development package can be installed by issuing the following command:

sudo apt-get -y install libopencv-dev

If you build the OpenCV library from sources and install it to a non-standard location, you can use the OpenCV_DIR CMake variable to specify the location where the OpenCVConfig.cmake files are located.

Example:

cmake -DOPENCV_DIR=$HOME/OpenCV/lib ..

If CMake fails to find the OpenCV library, you either have to install the OpenCV development package or to build the OpenCV library from sources.

If you build the OpenCV library from sources and install it to a non-standard location, you can use the OpenCV_DIR CMake variable to specify the location where the OpenCVConfig.cmake files are located.

Example:

cmake -DOPENCV_DIR=$HOME/OpenCV/lib ..

Point Cloud Libraryのインストール#

You can download the PCL All-in-one Installer for Windows here: https://github.com/PointCloudLibrary/pcl/releases

Make sure that you download a version of the PCL that is compatible with the Visual Studio version you are going to use.

If CMake fails to find the PCL, set the PCL_DIR variable to the folder containing the PCLConfig.cmake file.

Examples

  1. Open the CMakeSettings.json file (CMake -> Change CMake Settings -> "Stereo ace samples").
  2. Add -DPCL_DIR=\"C:\\Program Files\\PCL 1.9.1\\cmake\" to the cmakeCommandArgs list:
  "configurations": [
    {
      "name": "x64-Debug",
      ...
      "cmakeCommandArgs": "-DPCL_DIR=\"C:\\Program Files\\PCL 1.9.1\\cmake\"",
      ...
    },
    {
      "name": "x64-Release",
      ...
      "cmakeCommandArgs": "-DPCL_DIR=\"C:\\Program Files\\PCL 1.9.1\\cmake\"",
      ...
    }
  ]
  1. Open the CMake Settings dialog (Project -> CMakeSettings for "Stereo ace samples").
  2. Enter the following string in the CMake command arguments field:
    -DPCL_DIR="C:\Program Files\PCL 1.14.0\cmake".
  3. Press Ctrl+S to save the changes.

Before you can access the PCL_DIR in the CMake GUI, make sure that the Grouped check box is deselected in the CMake GUI.

Enter the following command to use CMake from the command line:

cmake -DPCL_DIR="C:\Program Files\PCL 1.14.0\cmake" ..

If the PCL is installed using the PCL All-in-one Installer, the installer takes care of adding the PCL bin directory to the PATH environment variable. If you're using a different installation method, you have to add the bin directory to the PATH environment variable yourself.

The PCL All-in-one Installer installs the OpenNI2.dll into the %ProgramFiles%\OpenNI2\Redist folder. The DLL is required at runtime. Either add this folder to your PATH environment variable, or copy the OpenNI2.dll to the folder the PCL binaries are located, e.g., %ProgamFiles%\PCL 1.13.0\bin.

If CMake fails to find the PCL library, you either have to install the libpcl development package or to build the PCL library from sources.

On Ubuntu systems, the libpcl development package can be installed by issuing the following command:

sudo apt-get -y install libpcl-dev

If you build the PCL from sources and install it to a non-standard location, the PCL_DIR CMake variable can be used to specify the location where the PCLConfig.cmake files is located.

Example:

cmake -DPCL_DIR=$HOME/PCL/cmake ..

Info

Samples using the Point Cloud Library (PCL) may crash depending on the versions of the PCL and VTK libraries installed on your system. The crash is due to a bug in the VTK libraries that are used by PCL for 3D visualization.
Source: https://github.com/PointCloudLibrary/pcl/issues/5237
Solution: PCL 1.13.1 contains fixes to work around the VTK bug.
Update to PCL 1.13.1 or higher. If required, uninstall the PCL libraries provided by your Linux distribution and build PCL version 1.13.1 or higher from sources (these can be retrieved from https://github.com/PointCloudLibrary/pcl).

If CMake fails to find the PCL library, you either have to install the PCL development package or to build the PCL library from sources.

If you build the PCL from sources and install it to a non-standard location, the PCL_DIR CMake variable can be used to specify the location where the PCLConfig.cmake files is located.

Example:

cmake -DPCL_DIR=$HOME/PCL/cmake ..

Info

Samples using the Point Cloud Library (PCL) may crash depending on the versions of the PCL and VTK libraries installed on your system. The crash is due to a bug in the VTK libraries that are used by PCL for 3D visualization.
Source: https://github.com/PointCloudLibrary/pcl/issues/5237
Solution: PCL 1.13.1 contains fixes to work around the VTK bug.
Update to PCL 1.13.1 or higher. If required, uninstall the PCL libraries provided by your Linux distribution and build PCL version 1.13.1 or higher from sources (these can be retrieved from https://github.com/PointCloudLibrary/pcl).

サンプル一覧#

  • FirstSample: Stereo ace カメラの操作方法と 3D データの取得に関するイントロダクション。
  • ParametrizeCamera: カメラパラメータへのアクセス方法を示します。
  • DeviceRemovalHandling: デバイス取り外しの処理方法について説明します。
  • OpenDeviceByIpAddress: IP アドレスのいずれかを使用して Stereo ace カメラを開く方法を示します。
  • GrabDepthMap: 深度マップの取得と解釈の方法について説明します。
  • SavePointcloud: OpenCVを使用せずに、カラー点群を .ply ファイルに保存する方法について説明します。
  • SavePointcloudCV: OpenCVを使用して、輝度画像、視差画像、およびカラー点群をファイルに保存する方法について説明します。
  • ShowPointcloud: Stereo ace カメラで取得した点群を視覚化する方法について説明します。
  • TriggerLowLatency: カメラの強度解像度と深度解像度を High(2x2 Binning)に設定することで、レイテンシを削減する方法を示します。
  • LeftAndRightIntensity: Stereo ace カメラから左右の輝度画像を取得する方法を示します。

詳細については、C++ サンプルディレクトリ内のサンプルコードを参照してください。

アプリケーションのビルド方法#

Using Visual Studio Solutions#

Refer to the Common Settings for Building Applications with pylon section of the pylon C++ Programmer's Guide to learn how to set up a project for building applications using pylon.

CMakeの使用#

Stereo ace 用 pylon サプリメンタリパッケージには、以下が含まれています: Findpylon.cmake pylon および Stereo ace 用 pylon サプリメンタリパッケージのインストール場所を特定するために使用されるモジュール。find モジュールは、以下をエクスポートします: pylon::pylon CMakeターゲットをエクスポートします。このターゲットを引数として target_link_librariesに渡すと、CMakeがインクルードパスやライブラリパスなどの設定を行います。

基本的な CMakeLists.txt CMakeファイルは次のようになります。

project (hello)

# Locate the CMake find module for pylon ...
# for Unix systems. All other OS PYLON_ROOT will be empty.
list(APPEND CMAKE_PREFIX_PATH $ENV{PYLON_ROOT})
# for Windows systems. All other OS PYLON_DEV_DIR will be empty.
list(APPEND CMAKE_PREFIX_PATH $ENV{PYLON_DEV_DIR})

find_package(pylon 12.0 REQUIRED)

add_executable(hello helloworld.cpp)
target_link_libraries(hello pylon::pylon)
project (hello)

# Locate the CMake find module for pylon ...
# for Unix system. All other OS PYLON_ROOT will be empty
list(APPEND CMAKE_PREFIX_PATH $ENV{PYLON_ROOT})
# for Windows system. All other OS PYLON_DEV_DIR will be empty
list(APPEND CMAKE_PREFIX_PATH $ENV{PYLON_DEV_DIR})

find_package(pylon 12.0 REQUIRED)

add_executable(hello helloworld.cpp)
target_link_libraries(hello pylon::pylon)
project (hello)

# Locate the CMake find module for pylon ...
# for Unix system. All other OS PYLON_ROOT will be empty
list(APPEND CMAKE_PREFIX_PATH $ENV{PYLON_ROOT})
# for Windows system. All other OS PYLON_DEV_DIR will be empty
list(APPEND CMAKE_PREFIX_PATH $ENV{PYLON_DEV_DIR})

find_package(pylon 12.0 REQUIRED)

add_executable(hello helloworld.cpp)
target_link_libraries(hello pylon::pylon)

Stereo ace 用 Instant Camera クラス#

pylonには、カメラデバイスにアクセスするためのさまざまなタイプのクラスが用意されています。ローレベルの IPylon デバイスのほかに、 Instant Camera クラスがあり、カメラ用の便利な高水準APIを提供しています。

イメージ Pylon::CInstantCamera クラスは、すべての Basler カメラへの汎用的なアクセスを提供します。

Stereo ace カメラの場合、Stereo ace 用 pylon サプリメンタリパッケージには以下が含まれています: Pylon::CStereoAceInstantCamera クラス。Basler では、パラメータへの便利なアクセスや Stereo ace 固有の機能を提供するため、Basler Stereo ace カメラに対してこのクラスの使用を推奨しています。

次を使用する場合: CBaslerUniversalInstantCamera クラスの代わりに CStereoAceInstantCamera クラスを使用すると、Stereo ace カメラが提供するすべてのカメラパラメータを引き続き設定および取得できます。アクセサーオブジェクトが提供されていない場合は、 CBaslerUniversalInstantCamera クラスによって提供されるアクセサオブジェクトがない場合は、 汎用パラメータアクセスを使用してください。 の Generic Parameter Access pylon C++ プログラマーズガイドのセクションを参照してください。

例:

using namespace Pylon;
GenApi::INodeMap& nodemap = camera.GetNodeMap();
CIntegerParameter depthSeg(nodemap, "BslDepthSeg" );
std::cout << "Segmentation: " << depthSeg.GetValue() << std::endl;

Stereo ace カメラを開いてアクセスする#

Stereo ace カメラオブジェクトを作成してオープンするには、3つの手順が必要です:

  1. アクセスするカメラのカメラオブジェクトを作成します。
    通常、次のインスタンスを作成する必要があります。 Pylon::CStereoAceInstantCamera クラス。
  2. 必要に応じて、Stereo ace 固有の設定イベントハンドラを登録します(詳細は DeviceRemovalHandling.cpp サンプルを参照してください)。
  3. カメラデバイスとの接続を確立するために、 Open() メソッドを呼び出します。

次の例は、これらの手順を示しています:

#include <pylon/PylonIncludes.h>
#include <pylon/StereoAceInstantCamera.h>
using namespace Pylon;

// ...

// Before using any pylon methods, the pylon runtime must be initialized.
PylonInitialize();

try {
    // 1: Create a camera object for the first available Stereo ace camera.
    CUniversalInstantInterface instantInterface(
        CInterfaceInfo().SetDeviceClass(Pylon::BaslerGenTlStaDeviceClass));
    CStereoAceInstantCamera camera(instantInterface.CreateFirstDevice());

    // 2. Register a default configuration if available (see samples).
    // camera.RegisterConfiguration(...);

    // 3. Open the camera, i.e., establish a connection to the camera device.
    camera.Open();

    // Use the camera.
    std::cout << "Connected to camera "
        << camera.GetDeviceInfo().GetFriendlyName() << std::endl;
    // ...

    // Close the connection.
    camera.Close();
} catch (const GenICam::GenericException& e) {
    std::cerr << "Exception occurred: " << std::endl
        << e.GetDescription() << std::endl;
}

// Releases all pylon resources.
PylonTerminate();

エラーが発生した場合は、 GenICam::GenericException から継承された例外がスローされます。

一般的なエラー条件:

  • Stereo ace カメラが見つかりません: CreateFirstDevice() 関数は例外をスローします。
  • 別のアプリケーションによってすでにオープンされているなどの理由で、カメラをオープンできません: Open() メソッドは例外をスローします。

次のサブセクションでは、カメラオブジェクトを作成およびオープンする方法に関する詳細情報を提供します。

最初に見つかった Stereo ace カメラのカメラオブジェクトの作成#

使用します: Pylon::CTlFactory::CreateFirstDevice() メソッドを使用して、最初に見つかった Stereo ace カメラのカメラオブジェクトを作成します。競合を防ぐため、常に Stereo ace カメラ用の pylon デバイスクラス識別子を指定してください。 CreateFirstDevice() から、別のタイプのカメラ用のカメラオブジェクトが作成されます:

CUniversalInstantInterface instantInterface(
    CInterfaceInfo().SetDeviceClass(Pylon::BaslerGenTlStaDeviceClass));
CStereoAceInstantCamera camera(instantInterface.CreateFirstDevice());

Stereo ace カメラが見つからない場合は、カメラおよびネットワークアダプタの IP 設定を確認してください。ネットワークの設定方法の詳細については、Basler 製品ドキュメントの Network Configuration トピックを参照してください。

特定の Stereo ace カメラのカメラオブジェクトの作成#

特定の Stereo ace カメラをオープンする場合は、デバイスクラスに加えて他の Property を指定できます。

シリアル番号を指定して特定の Stereo ace カメラを開くには、次の行を使用します。

CUniversalInstantInterface instantInterface(
    CInterfaceInfo().SetDeviceClass(Pylon::BaslerGenTlStaDeviceClass));
CStereoAceInstantCamera camera(instantInterface.CreateFirstDevice(
    CDeviceInfo().SetSerialNumber("40410842")));

ユーザー定義名を使用して Stereo ace カメラを開くには、次の行を使用します。

CUniversalInstantInterface instantInterface(
    CInterfaceInfo().SetDeviceClass(Pylon::BaslerGenTlStaDeviceClass));
CStereoAceInstantCamera camera(instantInterface.CreateFirstDevice(
    CDeviceInfo().SetUserDefinedName("MyCamera")));

User-Defined Names

パラメータを使用して、カメラにユーザー定義名を割り当てることができます。 DeviceUserID パラメータ。これを行うには、pylon 3D Viewer または pylon API を使用します。

camera.DeviceUserID.SetValue("MyStereoAce");

IPアドレスによるデバイスの作成

現在、 CreateFirstDevice() 関数を使用してカメラの IP アドレスを指定することはできません。その理由は、現在 Pylon::CDeviceInfo() クラスには、カメラのIPアドレスに関する情報は含まれていません。

イメージ OpenDeviceByIpAddress サンプルは、IP アドレスの 1 つを指定して Stereo ace カメラを開く方法を示しています。

目的の Stereo ace カメラが見つからない場合は、プロパティに正しい値を使用しているかどうかを確認し、カメラおよびネットワークアダプターの IP 構成設定を確認してください。ネットワークの設定の詳細については、Basler 製品ドキュメントの ネットワーク構成 のトピックを参照してください。

Stereo ace カメラの列挙#

次のコードスニペットは、接続されているすべての Stereo ace カメラのリストを取得する方法を示しています。リストの各要素に対してカメラが開き、いくつかのカメラパラメータ値が出力されます。

#include <pylon/PylonIncludes.h>
#include <pylon/StereoAceInstantCamera.h>
#include <ostream>
using namespace Pylon;

// ....

// Before using any pylon methods, the pylon runtime must be initialized.
PylonInitialize();

// ....

// Enumerate all Stereo ace cameras.
CTlFactory& TlFactory = CTlFactory::GetInstance();
DeviceInfoList_t lstDevices;
DeviceInfoList_t filter;
filter.push_back(CDeviceInfo().SetDeviceClass(BaslerGenTlStaDeviceClass));
TlFactory.EnumerateDevices(lstDevices, filter);
if (!lstDevices.empty()) {
    DeviceInfoList_t::const_iterator it;
    for (it = lstDevices.begin(); it != lstDevices.end(); ++it) {
        std::cout << it->GetFullName();

        // Open camera, i.e., establish a connection to the camera device.
        CStereoAceInstantCamera camera(CTlFactory::GetInstance().CreateDevice(*it));
        // Optionally register configuration(s) here.
        camera.Open();

        // Print out some information.
        std::cout << "Connected to camera "
            << camera.GetDeviceInfo().GetFriendlyName() << std::endl;
        std::cout << "IP Address: "
            << camera.GevCurrentIPAddress.GetValue() << std::endl;
        std::cout << "User-defined name: "
            << camera.DeviceUserID.GetValue() << std::endl;
        std::cout << "Serial Number: "
            << camera.DeviceSerialNumber.GetValue() << std::endl;
}  // The connection will be closed automatically when leaving the scope here.
else {
    std::cerr << "No devices found!" << std::endl;
}

カメラ設定ハンドラーの登録#

pylon Instant Cameraクラスを使用すると、特定のイベント(例えば、 Open() メソッドが呼び出されたとき)にカメラ設定を適用するために使用できる、設定イベントハンドラーオブジェクトを登録できます。

次の例は、追加の設定を適用する設定イベントハンドラーを登録する方法を示しています:

class MyConfigurationHandler : public StereoAceConfigurationEventHandler
{
public:
    // Sets exposure time to minimum possible value.
    void OnOpened(CStereoAceInstantCamera& camera) override
    {
        camera.ExposureTime.SetToMinimum();
    }
};

// ....

// Then, register configuration event handlers.
camera.RegisterConfiguration(
      new MyConfigurationHandler,
      RegistrationMode_Append, Cleanup_Delete);

// ....

camera.Open(); // Configurations will be applied.

pylon カメライベントハンドラクラスの詳細については、pylon C++ プログラマーズガイドの インスタントカメライベントハンドラの基礎 セクションを参照してください。

設定イベントハンドラを指定して目的の設定を適用したくない場合は、次の処理の呼び出し後であればいつでも、変更するパラメータを設定できます。 CStereoAceInstantCamera::Open() メソッドを呼び出してカメラとの接続を確立します。

カメラパラメータの設定および取得方法の詳細については、カメラのパラメータ設定 セクションを参照してください。

カメラへの接続#

カメラオブジェクトを作成し、設定イベントハンドラーを登録した後、 CStereoAceInstantCamera::Open() メソッドを呼び出してカメラとの接続を確立します。

接続は、 CStereoAceInstantCamera::Close() メソッドが呼び出されます。 CStereoAceInstantCamera のデストラクターは、 Close() が明示的に呼び出されていない場合、自動的にそれを呼び出します。

カメラから定期的にハートビートリクエストを受信しない場合、カメラは接続を閉じます。ハートビートリクエストの欠落は、アプリケーションがクラッシュした場合やデバッガーによって中断された場合に発生します。

カメラのパラメータ設定#

pylon API を使用したカメラパラメータへのアクセス方法に慣れるには、pylon C++ プログラマーズガイドの パラメータへのアクセス セクションを参照してください。

pylon C++ サンプルの Parametrize_NativeParameterAccess および Parametrize_GenericParameterAccess は、pylon を使用してカメラパラメータにアクセスするための一般的な方法を示しています。

次のコードサンプルは、頻繁に使用される Stereo ace 固有のカメラパラメータを次の項目を使用して設定および取得する方法を示しています。 CStereoAceInstantCamera クラス。

// Include files to use the pylon API
#include <pylon/PylonIncludes.h>
#include <pylon/StereoAceInstantCamera.h>

// Namespaces for using the pylon API and the Stereo ace camera parameters
using namespace Pylon;
using namespace StereoAceCameraParams_Params;


// Set the exposure time of the camera.
camera.ExposureTime.SetValue(5000); // us

// Set the gain.
camera.Gain.SetValue(0.0);

// Set the illumination mode (e.g., AlwaysActive, AlternateActive, Off).
camera.BslIlluminationMode.SetValue(BslIlluminationMode_AlwaysActive);

// Set the illumination strength (0.0 ... 1.0).
camera.BslIlluminationStrength.SetValue(1.0);

// Set the minimum and maximum depth for the working area.
camera.BslDepthMinDepth.SetValue(200); // mm
camera.BslDepthMaxDepth.SetValue(2000); // mm

// Set the output resolutions.
CEnumParameter(camera.GetNodeMap(), "BslDepthResolution").SetValue("High");
CEnumParameter(camera.GetNodeMap(), "BslIntensityResolution").SetValue("Full");

// The producer derives the internal binning and scaling settings automatically.

// Print out current parameter values.
std::cout << "Exposure Time            : "
    << camera.ExposureTime.GetValue() << std::endl;
std::cout << "Gain                     : "
    << camera.Gain.GetValue() << std::endl;
std::cout << "Illumination Mode        : "
    << camera.BslIlluminationMode.GetValue() << std::endl;
std::cout << "Illumination Strength    : "
    << camera.BslIlluminationStrength.GetValue() << std::endl;
std::cout << "Min Depth                : "
    << camera.BslDepthMinDepth.GetValue() << std::endl;
std::cout << "Max Depth                : "
    << camera.BslDepthMaxDepth.GetValue() << std::endl;
std::cout << "Depth Resolution         : "
    << CEnumParameter(camera.GetNodeMap(), "BslDepthResolution").ToString() << std::endl;
std::cout << "Intensity Resolution     : "
    << CEnumParameter(camera.GetNodeMap(), "BslIntensityResolution").ToString() << std::endl;

pylon 3D Viewer には Documentation ペインが用意されています。Features ペインでカメラパラメータを選択すると、Documentation ペインに、選択したパラメータに関する情報や、そのカメラパラメータの値を取得および設定する方法を示す C++ および C# のコードスニペットが表示されます。

データの取得#

pylon API を使用したデータの取得方法については、pylon C++ Programmer's Guide の Grabbing Images セクションを参照してください。

pylon は、取得した画像を GrabResults と呼ばれるデータ構造として表します。Stereo ace カメラによって取得された GrabResults には、複数のコンポーネントが含まれています。デフォルトでは、各 GrabResult は輝度画像、視差図、および追加情報を格納します。

// Enable disparity maps by enabling the Disparity component and setting the
// appropriate pixel format.
camera.ComponentSelector.SetValue(ComponentSelector_Disparity);
camera.ComponentEnable.SetValue(true);

詳細については、Basler 製品ドキュメントの Component Selector および Pixel Format のトピックを参照してください。

グラブループ#

pylonは、グラブループを設定するためのさまざまなアプローチをサポートし、メモリバッファを処理するためのさまざまな戦略を提供します。

詳細については、pylon C++ Programmer's Guide の Grabbing Images セクションを参照してください。

次のコードスニペットは、次を使用した一般的なグラブ ループを示しています。 CStereoAceInstantCamera クラス:

#include <pylon/PylonIncludes.h>
#include <pylon/StereoAceInstantCamera.h>

using namespace Pylon;
using namespace StereoAceCameraParams_Params;


PylonInitialize();

CUniversalInstantInterface instantInterface(
    CInterfaceInfo().SetDeviceClass(Pylon::BaslerGenTlStaDeviceClass));
CStereoAceInstantCamera camera(instantInterface.CreateFirstDevice());
camera.Open();

size_t nBuffersGrabbed = 0;

// This smart pointer will receive the grab result data.
CGrabResultPtr ptrGrabResult;

camera.StartGrabbing();

while (camera.IsGrabbing() && nBuffersGrabbed < 10) {
    // Wait for an image and then retrieve it. A timeout of 1000 ms is used.
    camera.RetrieveResult(1000, ptrGrabResult, TimeoutHandling_ThrowException);

    // Data grabbed successfully?
    if (ptrGrabResult->GrabSucceeded()) {
        nBuffersGrabbed++;
        // Access the data.
        // ...existing code...
    } else {
        // Error handling
        std::cerr << "Grab error occurred: "
            << ptrGrabResult->GetErrorDescription() << std::endl;
    }
}
// Clean-up
camera.StopGrabbing();
camera.Close();

コンポーネントへのアクセス#

GrabResult の個々の画像コンポーネントにアクセスするには、次のメソッドを使用します。 Pylon::CGrabResultData::GetFirstImageDataComponent() メソッドを使用して、目的のコンポーネントタイプを指定します。このメソッドは、 Pylon::CPylonDataComponent を返します。これには、深度値などの画像データとそのメタデータが保持されます。

パラメーターを throwIfNotFound 引数を次のように指定します。 false 、欠落しているコンポーネントが例外をスローする代わりに無効なコンポーネントを返す場合。常に次のメソッドを使用してください。 CPylonDataComponent::IsValid() メソッドを使用して、データをアクセスする前に要求されたコンポーネントが見つかったかどうかを確認します。

複数のコンポーネントを含む GrabResults へのアクセス方法の詳細については、pylon C++ プログラマーズガイドの「Advanced Topics」章にある マルチコンポーネント画像取得結果 (Multi-Component Grab Results) セクションを参照してください。

例:

if (ptrGrabResult->GrabSucceeded()) {
    const auto intensityComponent =
        ptrGrabResult->GetFirstImageDataComponent(
            EComponentType::ComponentType_Intensity, 0, false);
    if (!intensityComponent.IsValid()) {
        throw std::runtime_error(
            "Buffer doesn't contain an intensity component.");
    }

    const auto disparityComponent =
        ptrGrabResult->GetFirstImageDataComponent(
            EComponentType::ComponentType_Disparity, 0, false);
    if (!disparityComponent.IsValid()) {
        throw std::runtime_error(
            "Buffer doesn't contain a disparity component.");
    }

} else {
    std::cerr << "Grab error: " << ptrGrabResult->GetErrorCode() << " "
              << ptrGrabResult->GetErrorDescription() << std::endl;
}