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

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

このトピックでは、バーゼルに特化した情報を提供します。 Stereo mini カメラに関するものであり、pylon C++ API の包括的な概要を提供することを目的としていません。

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++のサンプルコードが利用可能です。

  • 最初のサンプル: 輝度と範囲のデータを取得し、中心ピクセル値を出力します。
    • 最初のStereo mini デバイスを使用する BaslerGenTlStmDeviceClass.
    • 強度と範囲のコンポーネントを有効にします。
    • 中心ピクセルの強度(RGBA)値と範囲値を読み取ります。
  • 深度マップを取得: OpenCVを使用して、距離データを色付きの深度マップに変換します。
    • 範囲コンポーネントを使用します(Coord3D_C16)。
    • OpenCVを使用して深度値を色付けし、リアルタイムで可視化します。
  • ShowPointCloud: PCLを使用して、リアルタイムのカラー点群を表示します。
    • 範囲コンポーネントを使用します(Coord3D_ABC32f)と色の強度。
    • 取得結果を変換して pcl::PointCloud<pcl::PointXYZRGB>.
    • リアルタイムの点群ビューアを表示します。
  • SavePointCloud: 1 つのカラーポイントクラウドを 。プライ ファイル。
    • 1フレームをキャプチャし、カラー点群をエクスポートします。 pointcloud_color.ply.

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

  • 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:

sudo apt -y install build-essential cmake libopencv-dev libpcl-dev libboost-all-dev

サンプルを作成する方法#

情報

サンプルを作成する前に、サンプルフォルダを読み書き権限のある場所にコピーしてください。

すべてのC++サンプルは、ビルドシステムとしてCMakeを使用しています。

  1. Start Visual Studio.
  2. On the start page, choose Open Folder (or Open a local folder) and navigate to the copied sample folder.
  3. Open the cpp subfolder and click the Select Folder button.
  4. Choose your preferred configuration from the configuration dropdown.
  5. Press Ctrl+Shift+B to build all samples.
  1. Start CMake GUI.
  2. In the Where is the source code field, enter the path to the cpp subfolder of your samples.
  3. In the Where to build the binaries field, enter a path where you want to store the build output.
  4. Click Configure.
  5. Choose your Visual Studio version from the dropdown and click Finish.
  6. Click Generate.
  7. In the File Explorer, navigate to your build folder and double-click the generated Visual Studio solution file (.sln) to open it.
  8. In Visual Studio, press Ctrl+Shift+B to build all samples.
  1. Create a build directory:
    mkdir build && cd build
  2. Run CMake:
    cmake ..
  3. Build the samples:
    make
  4. 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):

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

Adding OpenCV to PATH Environment Variable#

Add the OpenCV bin directory to PATH, for example:

C:\Program Files\OpenCV\build\x64\vc16\bin

If CMake doesn't find OpenCV, install the OpenCV development package or build OpenCV from source.

On Ubuntu systems, install the package with:

sudo apt-get -y install libopencv-dev

If OpenCV is installed in a non-standard location, set OpenCV_DIR accordingly:

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

ポイントクラウドライブラリのインストール#

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):

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

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:

sudo apt-get -y install libpcl-dev

If PCL is installed in a non-standard location, set PCL_DIR accordingly:

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

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プロジェクトの使用#

CMakeを使用する#

のStereo mini サンプルでは、​​以下のCMake設定を使用します。

  • find_package(pylon 10.0 REQUIRED)
  • オプション find_package(OpenCV QUIET) 深度マップの可視化
  • オプション find_package(PCL QUIET) 点群可視化用

最小限の CMake プロジェクトStereo mini アプリケーションは次のようになります。

cmake_minimum_required(VERSION 3.21)
project(stereo_mini_app LANGUAGES CXX)

# Locate pylon on Windows
list(APPEND CMAKE_PREFIX_PATH $ENV{PYLON_DEV_DIR})

find_package(pylon 10.0 REQUIRED)

add_executable(stereo_mini_app main.cpp)
target_link_libraries(stereo_mini_app PRIVATE pylon::pylon)
cmake_minimum_required(VERSION 3.21)
project(stereo_mini_app LANGUAGES CXX)

# Locate pylon on Linux
list(APPEND CMAKE_PREFIX_PATH $ENV{PYLON_ROOT})

find_package(pylon 10.0 REQUIRED)

add_executable(stereo_mini_app main.cpp)
target_link_libraries(stereo_mini_app PRIVATE pylon::pylon)

アプリケーションがサンプルと同じオプションの依存関係を使用する場合は、それらを条件付きで追加してください。

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()

コマンドラインからビルドするには:

mkdir -p build
cd build
cmake ..
cmake --build .

カメラ機能へのアクセス#

デバイスを開く#

VisualAppletsデザインの主要なデータ形式として、 Pylon::CTlFactory::CreateFirstDevice() 最初の利用可能なカメラオブジェクトを作成する方法Stereo mini カメラ。常にパイロンデバイスクラス識別子を指定します。 Stereo mini 防ぐためのカメラ 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 C++ プログラマーズ ガイドの「画像の取得」セクションを参照して、データ取得の方法を理解してください。 pylon API 。

pylon は、取得した画像を GrabResults と呼ばれるデータ構造として表現します。 Stereo ace カメラは複数のコンポーネントで構成されています。デフォルトでは、各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つ以上のコンポーネントを格納できます。コンテナを使用して、コンポーネントの数を照会したり、特定のコンポーネントを取得したりできます。コンテナ内の各コンポーネントは、深度値などの実際のデータとメタデータを保持します。

VisualAppletsデザインの主要なデータ形式として、 Pylon::CGrabResultData::GetDataContainer() GrabResult にアクセスする方法 CPylonDataContainer. 使用する Pylon::CPylonDataContainer::GetDataComponent() コンポーネントのインデックスを指定してコンポーネントにアクセスする方法。

pylon が複数のコンポーネントを含む GrabResult にアクセスする方法の詳細については、 pylon C++ プログラマーズ ガイドの「高度なトピック」章にある「マルチコンポーネントの Grab Results」セクションを参照してください。

深度データへのアクセス#

Stereo mini カメラは深度データを提供します Range コンポーネント。選択したピクセルフォーマットに応じて、範囲データは次のように利用できます。

  • Coord3D_C16 16ビット深度値の場合
  • Coord3D_ABC32f 直接3D座標の場合(X, Y, Z 浮遊物)
camera.ComponentSelector.FromString("Range");
camera.PixelFormat.FromString("Coord3D_C16");

使用pylon API#

pylon C++ API の使用方法に関するより詳細な情報については、 Stereo mini カメラについては、 pylon C++ プログラマーズ ガイドを参照してください。