C++ プログラマーズガイド#
pylonを初めて使用する場合は、pylon C++プログラマーズガイドのはじめにセクションを読んで、まず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
- オプション:OpenCVライブラリ
- オプション:Point Cloud Library (PCL)
サンプルのビルド#
- Copy the Development\Samples\Stereo_ace\C++ folder to a location where you have write permissions.
- Launch Microsoft Visual Studio.
- 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:
OpenCVまたはPCLが見つからない場合、CMakeは不足しているライブラリを必要とするサンプルのみをスキップします。その他のサンプルは引き続きビルドできます。
サンプルのビルドや実行で問題が発生した場合は、トラブルシューティングトピックを確認してください。
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
- Open the CMake Settings dialog (Project -> CMakeSettings for "Stereo ace samples")
- Enter the following command in the CMake command arguments field:
-DOpenCV_DIR="C:\Program Files\OpenCV\build\x64\vc16\lib" - 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.
Adding OpenCV to PATH Environment Variable#
You have to add the OpenCV bin directory to the PATH environment variable.
- Press the Win key.
- Type "environment".
- Click Edit environment variables for your account.
- In the User variables area, select Path.
- Click the Edit button.
- Click New.
- Enter the path of your OpenCV installation, e.g.:
C:\Program Files\OpenCV\build\x64\vc16\bin - 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:
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:
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:
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
- Open the CMakeSettings.json file (CMake -> Change CMake Settings -> "Stereo ace samples").
- Add
-DPCL_DIR=\"C:\\Program Files\\PCL 1.9.1\\cmake\"to thecmakeCommandArgslist:
- Open the CMake Settings dialog (Project -> CMakeSettings for "Stereo ace samples").
- Enter the following string in the CMake command arguments field:
-DPCL_DIR="C:\Program Files\PCL 1.14.0\cmake". - 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.

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:
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:
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:
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補足パッケージのインストール場所を特定するために使用されるモジュール。検索モジュールは以下をエクスポートします: 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 デバイスのほかに、カメラ用の便利な高レベルAPIを提供する、いわゆる Instant Camera クラスがあります。
イメージ 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つのステップがあります:
- アクセスするカメラのカメラオブジェクトを作成します。
通常は、Pylon::CStereoAceInstantCameraクラスのインスタンスを作成する必要があります。 - 必要に応じて、Stereo ace固有の設定イベントハンドラーを登録します(詳細については、DeviceRemovalHandling.cppサンプルを参照してください)。
- アプリケーションで
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 Viewerの 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 parameter です。これは pylon 3D Viewer または pylon API で実行できます。
Creating a Device by Its IP Address
現在、カメラのIPアドレスを指定することはできません。 CreateFirstDevice() 関数を使用します。その理由は、現在、 Pylon::CDeviceInfo() クラスにはカメラのIPアドレスに関する情報が含まれていないためです。
イメージ OpenDeviceByIpAddress サンプルは、IP アドレスのいずれかを使用して Stereo ace カメラを開く方法を示しています。
目的の Stereo ace カメラが見つからない場合は、Property に適切な値が使用されているかどうか、およびカメラとネットワークアダプターの IP 設定をご確認ください。ネットワークの設定方法の詳細については、Basler 製品ドキュメントの「Network Configuration」トピックをご参照ください。
Stereo aceカメラの列挙#
次のコードスニペットは、接続されているすべての Stereo ace カメラのリストを取得する方法を示しています。リストの各要素についてカメラが開き、いくつかのカメラ parameter 値が出力されます。
#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++ プログラマーズガイドの「Instant Camera Event Handler Basics」セクションをご参照ください。
構成イベントハンドラーを提供して希望の設定を適用したくない場合は、次の呼び出し後いつでも変更する parameter を設定できます。 CStereoAceInstantCamera::Open() メソッドの呼び出し後、いつでも変更したいパラメータを設定できます。
カメラ parameter の値の設定および取得方法の詳細については、「Parametrize Camera」セクションをご参照ください。
カメラへの接続#
カメラオブジェクトを作成し、設定イベントハンドラーを登録した後、 CStereoAceInstantCamera::Open() メソッドの呼び出し後、いつでも変更したいパラメータを設定できます。
を呼び出すことでカメラとの接続が確立されます。
接続は、 CStereoAceInstantCamera::Close() メソッドが呼び出されるまで維持されます。 CStereoAceInstantCamera のデストラクターは、明示的に呼び出されていない場合、自動的に Close() を呼び出します。
カメラからハートビートリクエストが定期的に受信されない場合、カメラは接続を閉じます。ハートビートリクエストの欠落は、アプリケーションがクラッシュした場合やデバッグツールによって中断された場合に発生します。
カメラのパラメータ設定#
pylon API を使用したカメラ parameter へのアクセス方法に慣れるには、pylon C++ プログラマーズガイドの「Accessing Parameters」セクションをご参照ください。
pylon C++ サンプルの Parametrize_NativeParameterAccess および Parametrize_GenericParameterAccess は、pylon を使用してカメラ parameter にアクセスする一般的な方法を示しています。
次のコードサンプルは、頻繁に使用される Stereo ace 固有のカメラ parameter を使用して設定および取得する方法を示しています。 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 ペインでカメラ parameter を選択すると、選択した parameter に関する情報、およびそのカメラ parameter の値を取得・設定する方法を示す C++ および C# のコードスニペットが Documentation ペインに表示されます。
データの取得#
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 によるアクセス方法の詳細については、pylon C++ プログラマーズガイドの「高度なトピック」章にある「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;
}