C++ 프로그래머 가이드#
pylon을 처음 사용하시는 경우, Basler에서는 pylon C++ Programmer's Guide의 Getting Started 섹션을 먼저 읽고 pylon C++ API에 익숙해질 것을 권장합니다.
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: 컬러 포인트 클라우드를 다음 형식으로 저장합니다: .ply 파일.
- 프레임 하나를 캡처하여 컬러 포인트 클라우드를 다음 위치로 내보냅니다.
pointcloud_color.ply.
- 프레임 하나를 캡처하여 컬러 포인트 클라우드를 다음 위치로 내보냅니다.
샘플 빌드 전제 조건#
- 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:
샘플 빌드 방법#
정보
샘플을 빌드하기 전에 읽기 및 쓰기 권한이 있는 위치로 샘플 폴더를 복사하십시오.
CMake는 모든 C++ 샘플의 빌드 시스템으로 사용됩니다.
- 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++ Programmer's Guide의 Grabbing Images 섹션을 참조하십시오.
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++ Programmer's Guide의 Grabbing Images 섹션을 참조하십시오.
다음 코드 조각은 다음을 사용하는 일반적인 그랩 루프를 보여줍니다. 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 클래스입니다. 컨테이너는 하나 이상의 구성 요소를 담을 수 있습니다. 컨테이너를 사용하여 구성 요소 수를 조회하고 특정 구성 요소를 검색할 수 있습니다. 컨테이너의 각 구성 요소는 실제 데이터(예: 깊이 값)와 메타데이터를 담고 있습니다.
다음 명령을 사용하여 Pylon::CGrabResultData::GetDataContainer() 메서드를 사용하여 GrabResult의 CPylonDataContainer. microDisplay의 Pylon::CPylonDataContainer::GetDataComponent() 메서드는 컴포넌트의 인덱스를 지정하여 해당 컴포넌트에 액세스할 수 있게 해줍니다.
여러 구성 요소를 포함하는 GrabResults에 대한 pylon의 액세스 제공 방식에 대한 자세한 내용은 pylon C++ Programmer's Guide의 Advanced Topics 챕터에 있는 Multi-Component Grab Results 섹션을 참조하십시오.
깊이 데이터 액세스#
Stereo mini 카메라는 다음을 통해 심도 데이터를 제공합니다. Range 구성 요소. 선택한 Pixel Format에 따라 범위 데이터를 다음과 같이 사용할 수 있습니다.
Coord3D_C1616비트 심도 값용Coord3D_ABC32f직접 3D 좌표(X, Y, Z부동 소수점)용
pylon API 사용하기#
Stereo mini 카메라에서 pylon C++ API를 사용하는 방법에 대한 자세한 내용은 pylon C++ Programmer's Guide를 참조하십시오.