read image from basler GigE camera in python

536 Views Asked by At

I try to read image from basler aca2500-14gc GigE camera in python but i can't this is my code

from pypylon import pylon
import cv2
camera = pylon.InstantCamera(pylon.TlFactory.GetInstance().CreateFirstDevice())
camera.Open()
camera.StartGrabbing(pylon.GrabStrategy_LatestImageOnly)
while camera.IsGrabbing():
    # Retrieve the next available image
    grab_result = camera.RetrieveResult(5000, pylon.TimeoutHandling_ThrowException)

    # Convert the image to OpenCV format
    img = grab_result.Array

    # Display the image in a window
    cv2.imshow('Basler Camera', img)
    # Wait for a key press to exit
    if cv2.waitKey(1) & 0xFF == ord('q'):
    break
camera.StopGrabbing()
camera.Close()
cv2.destroyAllWindows()

by the way this code work with basler aca4112-30uc USB3.0 camera So what i need to do to read image from GigE camera? I tried a few different ways but it didn't work

0

There are 0 best solutions below