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:
샘플 빌드 방법#
정보
샘플을 빌드하기 전에, 샘플 폴더를 읽기 및 쓰기 권한이 있는 위치로 복사하십시오.
모든 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 카메라로 획득한 GrabResults에는 여러 구성 요소가 포함되어 있습니다. 기본적으로 각 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 클래스. 컨테이너는 하나 이상의 컴포넌트를 포함할 수 있습니다. 컨테이너를 사용하여 컴포넌트의 개수를 조회하거나 특정 컴포넌트를 가져올 수 있습니다. 컨테이너 내의 각 컴포넌트는 실제 데이터(예: 수심 값)와 해당 메타데이터를 포함하고 있습니다.
다음 명령을 사용하여 Pylon::CGrabResultData::GetDataContainer() 메서드를 사용하여 GrabResult의 CPylonDataContainer. microDisplay의 Pylon::CPylonDataContainer::GetDataComponent() 메서드는 컴포넌트의 인덱스를 지정하여 해당 컴포넌트에 액세스할 수 있게 해줍니다.
pylon이 여러 구성 요소를 포함하는 GrabResults에 대한 액세스를 제공하는 방법에 대한 자세한 내용은 『 pylon C++ 프로그래머 가이드 』의 ‘고급 주제’ 장에 있는 ‘다중 구성 요소 Grab 결과’ 섹션을 참조하십시오.
깊이 데이터 액세스#
Stereo mini 카메라는 다음을 통해 깊이 데이터를 제공합니다. Range 구성 요소. 선택한 픽셀 형식에 따라 범위 데이터는 다음과 같은 형태로 제공됩니다:
Coord3D_C1616비트 색상 심도의 값에 대해Coord3D_ABC32f직접 3D 좌표의 경우 (X, Y, Zfloats)
다음 방법을 사용하여 pylon API#
Stereo mini 카메라에서 pylon C++ API를 사용하는 방법에 대한 자세한 내용은 pylon C++ 프로그래머 가이드를 참조하십시오.