Python 프로그래머 가이드#
공식 Basler pylon Python 언어 바인딩은 pypylon 프로젝트입니다. pypylon은 GitHub에서 호스팅되는 오픈 소스 프로젝트입니다. Basler Stereo ace 카메라를 사용하려면 버전 26.06 이상이 필요합니다.
pypylon을 처음 사용하는 경우, Basler에서는 먼저 pypylon documentation을 읽고 pypylon API에 익숙해질 것을 권장합니다.
Python 프로그래밍 샘플#
샘플 실행을 위한 사전 요구 사항#
- pylon 26.06 이상
- Python 3.9 이상
- pypylon 26.06 이상
각 샘플에는 다음이 포함되어 있습니다. requirements.txt 파일입니다. 샘플에 따라 pypylon 및 다음과 같은 선택적 종속성이 포함됩니다. NumPy, OpenCV, 또는 Open3D.
필요한 라이브러리를 설치하려면 Python 샘플 디렉토리로 이동하여 실행하려는 샘플에 대한 요구 사항을 설치하십시오.
python3 -m pip install -r SimpleGrab/requirements.txt
python3 -m pip install -r OpenDeviceByIpAddress/requirements.txt
python3 -m pip install -r LeftAndRightIntensity/requirements.txt
python3 -m pip install -r TriggerLowLatency/requirements.txt
python3 -m pip install -r ShowPointCloud/requirements.txt
샘플 실행#
Stereo ace용 pylon Supplementary Package에는 Python 및 pypylon을 사용하여 Stereo ace 카메라에 액세스하는 방법을 보여주는 몇 가지 Python 프로그래밍 샘플이 포함되어 있습니다.
The Python samples are located in the C:\Program Files\Basler\pylon\Development\Samples\Stereo_ace\Python folder.
The Python samples are located in the /opt/pylon/share/pylon/Samples/Stereo_ace/Python folder.
The Python samples are located in the /opt/pylon/share/pylon/Samples/Stereo_ace/Python folder.
정보
샘플을 빌드하기 전에 쓰기 권한이 있는 원하는 위치에 샘플이 포함된 폴더를 복사하십시오.
Python 샘플 디렉토리에서 Python을 사용하여 한 번에 하나의 샘플을 실행하십시오. 예:
python3 SimpleGrab/SimpleGrab.py
python3 OpenDeviceByIpAddress/OpenDeviceByIpAddress.py <ip-address>
python3 LeftAndRightIntensity/LeftAndRightIntensity.py
python3 TriggerLowLatency/TriggerLowLatency.py
python3 ShowPointCloud/ShowPointCloud.py
바꿔서 <ip-address> Stereo ace 카메라의 IP 주소 중 하나를 입력합니다.
예제 실행 중 문제가 발생하는 경우 Troubleshooting 항목을 확인하십시오.
예제 목록#
- SimpleGrab: Stereo ace 카메라에서 이미지를 획득하고 명도(intensity) 및 시차(disparity) 데이터에 액세스하는 방법을 설명합니다.
- ShowPointCloud: 시차 데이터로부터 포인트 클라우드를 계산하고 Open3D를 사용하여 시각화하는 방법을 설명합니다.
- OpenDeviceByIpAddress: IP 주소 중 하나를 사용하여 Stereo ace 카메라를 여는 방법을 보여줍니다.
- TriggerLowLatency: 카메라의 명도 및 깊이 해상도를 High(2x2 Binning)로 설정하여 지연 시간을 줄이는 방법을 보여줍니다.
- LeftAndRightIntensity: Stereo ace 카메라에서 좌측 및 우측 명도 이미지를 획득하는 방법을 보여줍니다.
자세한 내용은 Python 예제 디렉터리의 샘플 코드를 참조하십시오.
Stereo ace 카메라에서 pypylon을 사용하는 방법#
Stereo ace 카메라 열기 및 액세스#
다음 예제는 pypylon을 사용하여 사용 가능한 첫 번째 Stereo ace 카메라를 여는 방법을 보여줍니다.
from pypylon import pylon
# Open the first available Stereo ace camera.
di = pylon.DeviceInfo()
di.SetDeviceClass("BaslerGTC/Basler/basler_xw")
camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice(di))
camera.Open()
print(f"Connected to camera: {camera.GetDeviceInfo().GetModelName()}")
# Close the camera
camera.Close()
일련번호 또는 사용자 정의 이름을 사용하여 특정 Stereo ace 카메라를 열려면 다음을 수정하십시오. DeviceInfo 개체:
# Open a specific Stereo ace camera by serial number.
di.SetSerialNumber("12345678")
# Open a specific Stereo ace camera by user-defined name.
di.SetUserDefinedName("MyStereoAce")
카메라 Property 액세스#
다음을 사용하여 카메라 Property에 액세스하고 수정할 수 있습니다. camera 개체. 예를 들면 다음과 같습니다.
# Set the exposure time.
camera.ExposureTime.Value = 5000 # in microseconds
# Set the illumination mode.
camera.BslIlluminationMode.Value = "AlternateActive"
# Set the output resolutions.
camera.BslDepthResolution.Value = "High"
camera.BslIntensityResolution.Value = "Full"
# Print the current depth resolution.
print(f"Depth Resolution: {camera.BslDepthResolution.Value}")
데이터 취득#
다음 예제는 Stereo ace 카메라에서 명도 및 시차 데이터를 획득하는 방법을 보여줍니다.
import numpy as np
import cv2
from pypylon import pylon
# Open the first available Stereo ace camera.
di = pylon.DeviceInfo()
di.SetDeviceClass("BaslerGTC/Basler/basler_xw")
camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice(di))
camera.Open()
# Enable intensity and disparity components.
camera.ComponentSelector.Value = "Intensity"
camera.ComponentEnable.Value = True
camera.ComponentSelector.Value = "Disparity"
camera.ComponentEnable.Value = True
# Start grabbing
camera.StartGrabbing(pylon.GrabStrategy_LatestImageOnly)
while camera.IsGrabbing():
grabResult = camera.RetrieveResult(20000, pylon.TimeoutHandling_ThrowException)
if grabResult.GrabSucceeded():
# Access intensity and disparity data.
pylonDataContainer = grabResult.GetDataContainer()
intensityComponent = pylonDataContainer.GetFirstImageDataComponent(pylon.ComponentType_Intensity, 0, False)
disparityComponent = pylonDataContainer.GetFirstImageDataComponent(pylon.ComponentType_Disparity, 0, False)
if not intensityComponent.IsValid() or not disparityComponent.IsValid():
print("Missing intensity or disparity component in buffer.")
grabResult.Release()
continue
intensity = intensityComponent.Array.reshape(intensityComponent.Height, intensityComponent.Width)
disparity = disparityComponent.Array.reshape(disparityComponent.Height, disparityComponent.Width)
# Display the images.
cv2.imshow("Intensity", intensity)
cv2.imshow("Disparity", disparity)
# Break the loop on ESC key press.
if cv2.waitKey(1) & 0xFF == 27:
break
grabResult.Release()
camera.StopGrabbing()
camera.Close()
포인트 클라우드 계산#
Open3D를 사용하여 포인트 클라우드를 계산하고 시각화하는 방법의 예는 ShowPointCloud.py 예제를 참조하십시오.
애플리케이션 디버깅#
Stereo ace 카메라와 함께 pypylon을 사용하는 동안 문제가 발생하면 Troubleshooting 항목을 확인하십시오.