C++プログラマーズガイド#
pylonを初めて使用する場合は、まずpylon C++プログラマーガイドの入門セクションを読んで、pylon C++ APIに慣れることをBaslerはお勧めします。
C++プログラミングサンプル#
To open the folder containing the programming samples for Stereo mini cameras, press the Win key, go to the Basler folder, and choose Stereo mini Samples. A File Explorer window opens. The C++ programming samples are located in the cpp folder.
The C++ samples are located in the /opt/pylon/share/pylon/Samples/stereo-mini/cpp folder.
以下のStereo mini C++サンプルが利用可能です:
- FirstSample: 輝度およびレンジデータを取得し、中心ピクセルの値を出力します。
- 以下を使用して最初のStereo miniデバイスを開きます:
BaslerGenTlStmDeviceClass. - 輝度およびレンジコンポーネントを有効にします。
- 中心ピクセルの輝度(RGBA)およびレンジ値を読み取ります。
- 以下を使用して最初のStereo miniデバイスを開きます:
- GrabDepthMap: OpenCVを使用してレンジデータをカラー化されたデプスマップに変換します。
- レンジコンポーネントを使用します(
Coord3D_C16を使用します。 - リアルタイム表示のために、OpenCVを使用して深度値をカラー化します。
- レンジコンポーネントを使用します(
- ShowPointCloud: PCLを使用して、カラーのライブポイントクラウドを表示します。
- レンジコンポーネントを使用します(
Coord3D_ABC32f) およびカラー用の輝度。 - 取得結果を以下に変換します:
pcl::PointCloud<pcl::PointXYZRGB>. - ライブポイントクラウドビューワーを表示します。
- レンジコンポーネントを使用します(
- SavePointCloud: カラーのポイントクラウドを1つ保存します(形式: .ply ファイル。
- 1フレームをキャプチャし、カラーのポイントクラウドを以下にエクスポートします:
pointcloud_color.ply.
- 1フレームをキャプチャし、カラーのポイントクラウドを以下にエクスポートします:
サンプル構築の前提条件#
- Visual Studio 2019 or above
- pylon Software Suite with Stereo mini supplementary package
- Optional: OpenCV library
- Optional: Point Cloud Library (PCL)
- Optional: Boost libraries
- pylon Software Suite with Stereo mini supplementary package
- CMake 3.3 or above
- A C++ compiler (for example,
gcc/g++) - Optional: OpenCV
- Optional: Point Cloud Library (PCL)
- Optional: Boost libraries
On an Ubuntu system, you can install the prerequisites by issuing the following command:
サンプルの構築方法#
情報
サンプルをビルドする前に、サンプルフォルダを読み取りおよび書き込み権限のある場所にコピーしてください。
すべてのC++サンプルのビルドシステムとしてCMakeが使用されています。
- Start Visual Studio.
- On the start page, choose Open Folder (or Open a local folder) and navigate to the copied sample folder.
- Open the cpp subfolder and click the Select Folder button.
- Choose your preferred configuration from the configuration dropdown.
- Press Ctrl+Shift+B to build all samples.
- Start CMake GUI.
- In the Where is the source code field, enter the path to the cpp subfolder of your samples.
- In the Where to build the binaries field, enter a path where you want to store the build output.
- Click Configure.
- Choose your Visual Studio version from the dropdown and click Finish.
- Click Generate.
- In the File Explorer, navigate to your build folder and double-click the generated Visual Studio solution file (.sln) to open it.
- In Visual Studio, press Ctrl+Shift+B to build all samples.
- Create a build directory:
mkdir build && cd build - Run CMake:
cmake .. - Build the samples:
make - Optionally, install the samples:
sudo make install
OpenCVライブラリのインストール#
Download OpenCV from https://github.com/opencv/opencv/releases.
Make sure that you use an OpenCV version that matches your Visual Studio toolchain. If no matching prebuilt package is available, build OpenCV from source with your Visual Studio version.
If CMake doesn't find OpenCV automatically, set OpenCV_DIR to the directory that contains OpenCVConfig.cmake.
Example (CMake command line):
Adding OpenCV to PATH Environment Variable#
Add the OpenCV bin directory to PATH, for example:
Point Cloud Libraryのインストール#
Download PCL from https://github.com/PointCloudLibrary/pcl/releases.
Make sure that the PCL version matches your Visual Studio toolchain.
If CMake doesn't find PCL automatically, set PCL_DIR to the directory that contains PCLConfig.cmake.
Example (CMake command line):
If required by your installation method, add the PCL bin directory to PATH.
If CMake doesn't find PCL, install the PCL development package or build PCL from source.
On Ubuntu systems, install the package with:
If PCL is installed in a non-standard location, set PCL_DIR accordingly:
Info
Samples using PCL can crash depending on the installed PCL/VTK versions because of a known VTK issue used by PCL visualization. Source: https://github.com/PointCloudLibrary/pcl/issues/5237 Use PCL 1.13.1 or newer when possible.
サンプルの実行#
ビルド出力フォルダから実行可能ファイルを実行します。例:
./FirstSample/FirstSample
./GrabDepthMap/GrabDepthMap
./ShowPointCloud/ShowPointCloud
./SavePointCloud/SavePointCloud
アプリケーションの構築方法#
提供されているサンプルセットで示されているように、CMakeを使用して独自の Stereo mini C++アプリケーションを作成します。
IDEプロジェクトの使用#
For Visual Studio-based projects, refer to: Common Settings for Building Applications with pylon (Windows)
For Linux-based builds, refer to: Common Settings for Building Applications with pylon (Linux)
CMake の使用#
Stereo miniサンプルは、次の構成を持つCMakeセットアップを使用します。
find_package(pylon 10.0 REQUIRED)- オプション
find_package(OpenCV QUIET)深度マップの視覚化用 - オプション
find_package(PCL QUIET)ポイントクラウドの視覚化用
Stereo miniアプリケーション用の最小限のCMakeプロジェクトは、次のようになります。
アプリケーションがサンプルと同じオプショナル依存関係を使用する場合は、条件付きで追加します。
find_package(OpenCV QUIET)
find_package(PCL QUIET)
if (OpenCV_FOUND)
target_include_directories(stereo_mini_app PRIVATE ${OpenCV_INCLUDE_DIRS})
target_link_libraries(stereo_mini_app PRIVATE ${OpenCV_LIBS})
endif()
if (PCL_FOUND)
target_include_directories(stereo_mini_app PRIVATE ${PCL_INCLUDE_DIRS})
target_compile_definitions(stereo_mini_app PRIVATE ${PCL_DEFINITIONS})
target_link_libraries(stereo_mini_app PRIVATE ${PCL_LIBRARIES})
endif()
コマンドラインからビルドするには:
カメラ機能へのアクセス#
デバイスを開く#
設定するピクセルのカラーコンポーネントを指定するには、 Pylon::CTlFactory::CreateFirstDevice() 最初に利用可能な Stereo miniカメラのカメラオブジェクトを作成するメソッド。別のタイプのカメラのカメラオブジェクトが作成されないように、 Stereo miniカメラ用のpylonデバイスクラス識別子を常に指定してください: CreateFirstDevice() からカメラオブジェクトを作成します:
// Open first available Stereo mini camera
Pylon::CStereoMiniInstantCamera camera(
Pylon::CTlFactory::GetInstance().CreateFirstDevice(
Pylon::CDeviceInfo().SetDeviceClass(Pylon::BaslerGenTlStmDeviceClass)));
std::cout << "Using device: " << camera.GetDeviceInfo().GetFriendlyName() << std::endl;
camera.Open();
データの取得#
pylon APIを使用したデータの取得方法については、pylon C++プログラマーガイドの画像の取得セクションを参照してください。
pylonでは、取得した画像がGrabResultsと呼ばれるデータ構造として表されます。 Stereo aceカメラで取得されたGrabResultには複数のコンポーネントが含まれています。デフォルトでは、各GrabResultに強度画像、深度マップ、および追加情報が格納されます。
// Enable intensity image by enabling the Intensity component
camera.ComponentSelector.FromString("Intensity");
camera.ComponentEnable.SetValue(true);
画像の取得#
pylonは、グラブループを設定するためのさまざまなアプローチをサポートし、メモリバッファを処理するためのさまざまなストラテジを提供します。
詳細については、pylon C++プログラマーガイドの画像の取得セクションを参照してください。
次のコードスニペットは、以下を使用した一般的なグラブループを示しています。 CStereoMiniInstantCamera クラス:
camera.StartGrabbing();
Pylon::CGrabResultPtr ptrGrabResult;
camera.RetrieveResult(5000, ptrGrabResult, Pylon::TimeoutHandling_ThrowException);
if (ptrGrabResult->GrabSucceeded())
{
const auto intensity = ptrGrabResult->GetDataComponent(Pylon::EComponentType::ComponentType_Intensity);
const auto range = ptrGrabResult->GetDataComponent(Pylon::EComponentType::ComponentType_Range);
// Process components
}
コンポーネントへのアクセス#
GrabResultの個々のコンポーネントにアクセスするには、 Pylon::CPylonDataContainer および Pylon::CPylonDataComponent クラスを使用できます。コンテナには1つ以上のコンテナを格納できます。コンテナを使用して、コンポーネントの数を照会したり、特定のコンポーネントを取得したりできます。コンテナ内の各コンポーネントには、深度値などの実データと、そのメタデータが保持されます。
設定するピクセルのカラーコンポーネントを指定するには、 Pylon::CGrabResultData::GetDataContainer() メソッドを使用すると、GrabResultの CPylonDataContainerにアクセスできます。コンポーネントのインデックスを指定してコンポーネントにアクセスするには、 Pylon::CPylonDataContainer::GetDataComponent() メソッドを使用します。
pylonが複数コンポーネントを含むGrabResultへのアクセスを提供する仕組みの詳細については、pylon C++ Programmer's GuideのAdvanced Topics章にあるMulti-Component Grab Resultsセクションを参照してください。
深度データへのアクセス#
Stereo miniカメラは、 Range コンポーネントを介して深度データを提供します。選択したPixel Formatに応じて、レンジデータは次のように利用できます:
Coord3D_C1616ビット深度値の場合Coord3D_ABC32f直接3D座標の場合(X, Y, Zfloat)
pylon APIの使用#
Stereo miniカメラでのpylon C++ APIの使用に関する詳細については、pylon C++ Programmer's Guideを参照してください。