콘텐츠로 바로 가기
STAGING SERVER
DEVELOPMENT SERVER

Python 프로그래머 가이드#

이 섹션에서는 Basler Stereo ace 카메라와 관련된 특화된 정보를 제공합니다. 공식 Basler pylon Python 언어 바인딩에 대한 포괄적인 개요를 제공하기 위한 것은 아닙니다.

Basler pylon의 공식 Python 언어 바인딩은 pypylon 프로젝트입니다. pypylon은 GitHub에서 호스팅되는 오픈 소스 프로젝트입니다. Basler Stereo ace 카메라를 사용하려면 버전 26.06 이상이 필요합니다.

pypylon을 처음 사용하는 경우, 먼저 pypylon 문서를 읽고 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 주소 중 하나를 사용합니다.

샘플 실행 중에 문제가 발생하는 경우 문제 해결 항목을 확인하십시오.

샘플 목록#

  • SimpleGrab: Stereo ace 카메라에서 이미지를 캡처하고 강도(intensity) 및 시차(disparity) 데이터에 액세스하는 방법을 보여줍니다.
  • ShowPointCloud: 시스패리티(disparity) 데이터로부터 포인트 클라우드를 계산하고 Open3D를 사용하여 시각화하는 방법을 설명합니다.
  • OpenDeviceByIpAddress: IP 주소 중 하나를 사용하여 Stereo ace 카메라를 여는 방법을 보여줍니다.
  • TriggerLowLatency: 카메라에서 강도(intensity) 및 깊이(depth) 해상도를 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")

카메라 파라미터 액세스#

다음 항목을 사용하여 카메라 파라미터에 액세스하고 수정할 수 있습니다. 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()

포인트 클라우드 계산#

blaze 구성 이벤트 핸들러 클래스에 대한 자세한 내용은 다음을 참조하십시오. ShowPointCloud.py Open3D를 사용하여 포인트 클라우드를 계산하고 시각화하는 방법의 예제 샘플입니다.

애플리케이션 디버깅#

Stereo ace 카메라와 함께 pypylon을 사용하는 동안 문제가 발생하면 문제 해결 항목을 확인하십시오.