C++ 프로그래머 가이드#
pylon을 처음 사용하는 경우, 먼저 pylon C++ Programmer's Guide의 시작하기(Getting Started) 섹션을 읽고 pylon C++ API에 익숙해지는 것을 권장합니다.
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는 누락된 라이브러리가 필요한 샘플만 건너뜁니다. 다른 샘플은 계속 빌드할 수 있습니다.
샘플 빌드 및 실행 중 문제가 발생하면 문제 해결(Troubleshooting) 항목을 확인하십시오.
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: 깊이 맵(depth map)을 취득하고 해석하는 방법을 설명합니다.
- 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 Supplementary Package에는 다음이 포함되어 있습니다. Findpylon.cmake 모듈은 pylon 및 Stereo ace용 pylon Supplementary Package의 설치 위치를 확인하는 데 사용됩니다. 찾기 모듈은 다음을 내보냅니다. 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 Class#
pylon은 카메라 장치에 액세스하기 위한 다양한 유형의 클래스를 제공합니다. 로우 레벨 IPylon 장치 외에도, 카메라를 위한 편리한 하이 레벨 API를 제공하는 소위 Instant Camera 클래스가 있습니다.
The Pylon::CInstantCamera 클래스는 모든 Basler 카메라에 대한 일반적인 액세스를 제공합니다.
Stereo ace 카메라의 경우, Stereo ace용 pylon Supplementary Package에 다음이 포함됩니다. Pylon::CStereoAceInstantCamera 클래스. Basler는 편리한 파라미터 액세스 및 Stereo ace 전용 기능을 제공하므로 Basler Stereo ace 카메라에 이 클래스를 사용할 것을 권장합니다.
다음 기능을 사용하는 경우 CBaslerUniversalInstantCamera ... 대신 class CStereoAceInstantCamera 클래스를 통해 Stereo ace 카메라가 제공하는 모든 카메라 파라미터를 여전히 설정하고 가져올 수 있습니다. 제공되는 접근자(accessor) 객체가 없는 경우 CBaslerUniversalInstantCamera 클래스에서, 다음을 사용하십시오. 일반 파라미터 접근(generic parameter access) 에서 설명한 대로 이름으로 파라미터에 접근합니다. 일반 파라미터 접근(Generic Parameter Access) pylon C++ Programmer's Guide의 섹션입니다.
예:
using namespace Pylon;
GenApi::INodeMap& nodemap = camera.GetNodeMap();
CIntegerParameter depthSeg(nodemap, "BslDepthSeg" );
std::cout << "Segmentation: " << depthSeg.GetValue() << std::endl;
Stereo ace 카메라 열기 및 액세스하기#
Stereo ace 카메라 객체를 생성하고 여는 데는 세 단계가 소요됩니다.
- 접근하려는 카메라의 카메라 객체를 생성합니다.
일반적으로 다음의 인스턴스를 생성해야 합니다.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::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 카메라를 열려는 경우, 장치 클래스 외에 다른 속성을 지정할 수 있습니다.
일련 번호로 특정 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 매개변수입니다. pylon 3D Viewer 또는 pylon API에서 이 작업을 수행할 수 있습니다:
IP 주소로 장치 생성
현재는 다음을 사용하여 카메라 IP 주소를 지정할 수 없습니다. CreateFirstDevice() function. 그 이유는 현재 다음 항목에 Pylon::CDeviceInfo() class가 카메라의 IP 주소에 대한 어떠한 정보도 포함하고 있지 않기 때문입니다.
The OpenDeviceByIpAddress 이 샘플은 IP 주소 중 하나를 사용하여 Stereo ace 카메라를 여는 방법을 보여줍니다.
원하는 Stereo ace 카메라를 찾을 수 없는 경우 속성에 올바른 값을 사용하고 있는지 확인하고, 카메라 및 네트워크 어댑터의 IP 구성 설정을 확인하십시오. 네트워크 설정에 대한 자세한 내용은 Basler 제품 문서의 네트워크 구성 항목을 참조하십시오.
Stereo ace 카메라 열거#
다음 코드 조각은 연결된 모든 Stereo ace 카메라의 목록을 검색하는 방법을 보여줍니다. 목록의 각 요소에 대해 카메라가 열리고 일부 카메라 매개변수 값이 출력됩니다.
#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() method 호출 시) 발생 시 카메라 설정을 적용하는 데 사용할 수 있는 구성 이벤트 핸들러 객체를 등록할 수 있습니다.
다음 예제는 추가 설정을 적용하는 구성 이벤트 핸들러를 등록하는 방법을 보여줍니다.
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 섹션을 참조하십시오.
구성 이벤트 핸들러를 제공하여 원하는 설정을 적용하지 않으려면, 다음 함수를 호출한 후 언제든지 변경하려는 매개변수를 설정할 수 있습니다. CStereoAceInstantCamera::Open() 메서드를 호출하여 매개변수를 설정할 수 있습니다.
카메라 매개변수 값을 설정하고 가져오는 방법에 대한 정보는 Parametrize Camera 섹션을 참조하십시오.
카메라 연결#
카메라 객체를 생성하고 구성 이벤트 핸들러를 등록한 후, 다음 메서드를 호출하여 CStereoAceInstantCamera::Open() 메서드를 호출하여 매개변수를 설정할 수 있습니다.
카메라와의 연결이 수립됩니다. 연결은 다음 CStereoAceInstantCamera::Close() 메서드가 호출될 때까지 유지됩니다. CStereoAceInstantCamera 의 소멸자는 명시적으로 호출되지 않은 경우 Close() 을(를) 자동으로 호출합니다.
카메라가 하트비트 요청을 주기적으로 수신하지 않으면 카메라는 연결을 닫습니다. 하트비트 요청 누락은 응용 프로그램이 중단되거나 디버거에 의해 중단될 때 발생합니다.
카메라 파라미터 설정#
pylon API를 사용하여 카메라 매개변수에 엑세스하는 방법을 숙지하려면 pylon C++ 프로그래머 가이드의 Accessing Parameters 섹션을 참조하십시오.
pylon C++ 샘플인 Parametrize_NativeParameterAccess 및 Parametrize_GenericParameterAccess는 pylon을 사용하여 카메라 매개변수에 액세스하는 일반적인 방법을 보여줍니다.
다음 코드 샘플은 다음 항목을 사용하여 자주 사용되는 Stereo ace 전용 카메라 매개변수를 설정하고 가져오는 방법을 보여줍니다. 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 창에서 카메라 매개변수를 선택하면 Documentation 창에 선택한 매개변수에 대한 정보와 해당 카메라 매개변수의 값을 가져오고 설정하는 방법을 보여주는 C++ 및 C# 코드 조각이 표시됩니다.
데이터 획득#
pylon API를 사용하여 데이터를 획득하는 방법을 익히려면 pylon C++ Programmer's Guide의 Grabbing Images 섹션을 참조하십시오.
pylon은 캡처된 이미지를 GrabResults라는 데이터 구조로 표현합니다. Stereo ace 카메라로 획득한 GrabResults에는 여러 구성 요소가 포함됩니다. 기본적으로 각 GrabResult는 강도 이미지, 디시티맵(disparity map) 및 추가 정보를 저장합니다.
// 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() 메서드를 사용하여 데이터에 액세스하기 전에 요청한 구성 요소가 발견되었는지 확인하십시오.
pylon이 여러 구성 요소가 포함된 GrabResults에 대한 액세스를 제공하는 방법에 대한 자세한 내용은 pylon C++ 프로그래머 가이드의 "Advanced Topics" 장에 있는 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;
}