콘텐츠로 바로 가기
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 보충 패키지에는 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 카메라에서 이미지를 캡처하고, 밝기 및 시차 데이터에 접근하는 방법을 보여줍니다.
  • ShowPointCloud: 디스패리티 데이터로부터 포인트 클라우드를 계산하고 Open3D를 사용하여 이를 시각화하는 방법을 보여줍니다.
  • OpenDeviceByIpAddress: Stereo ace 카메라의 IP 주소 중 하나를 사용하여 카메라를 여는 방법을 보여줍니다.
  • TriggerLowLatency: 카메라의 강도 및 깊이 해상도를 ‘높음’(2x2 비닝)으로 설정하여 지연 시간을 줄일 수 있는 방법을 보여줍니다.
  • 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을 사용하다가 문제가 발생하면 ‘문제 해결’ 항목을 확인해 보세요.