Ejemplo n.º 1
0
def find_cameras(serial_numbers):

    if len(serial_numbers) == 0:
        print('No serial numbers found. Enter them before starting.')

    try:
        tlFactory = pylon.TlFactory.GetInstance()

        # get all attached devices
        devices = tlFactory.EnumerateDevices()

        # look for unique devices that match the serial numbers
        camera_devices = []
        for device in devices:
            sn = device.GetSerialNumber()

            for _sn in serial_numbers:
                if sn == _sn:
                    camera_devices.append(device)
                    serial_numbers.remove(sn)
                    break

        camera_devices = tuple(camera_devices)

        # exit if no camera found
        if len(camera_devices) == 0:
            raise pylon.RuntimeException("No camera present.")

    except genicam.GenericException as e:
        print("An exception occurred.")
        print(e.GetDescription())

    return tlFactory, camera_devices
    def __init__(self, controller: Controller, binning_factor=4, max_cam_count=10, acquisition_timeout=1000, retrieval_timeout=5000, timeout=1):
        super().__init__()
        self._controller = controller
        self._camera_id = f'camera_{uuid.uuid4()}'
        controller.register_sensor(self, self._camera_id)
        self._acquisition_timeout = acquisition_timeout
        self._retrieval_timeout = retrieval_timeout
        self._timeout = timeout

        self._run = False
        self._active = False

        self._tl_factory = pylon.TlFactory.GetInstance()
        devices = self._tl_factory.EnumerateDevices()
        if len(devices) == 0:
            raise pylon.RuntimeException('No cameras attached.')
        self._cameras = pylon.InstantCameraArray(min(len(devices), max_cam_count))

        for i, cam in enumerate(self._cameras):
            cam.Attach(self._tl_factory.CreateDevice(devices[i]))
            # Print the model name of the camera.
            print("Using device ", cam.GetDeviceInfo().GetModelName())

        self._camera.PixelFormat = "RGB8"
        self._camera.BinningHorizontal = binning_factor
        self._camera.BinningVertical = binning_factor
    def get_single_measurement(self):
        self._measure_value()
        grab_result = self._camera.RetrieveResult(self._retrieval_timeout, pylon.TimeoutHandling_ThrowException)

        if grab_result.GrabSucceeded():
            img = grab_result.Array
            grab_result.Release()
            return img
        else:
            raise pylon.RuntimeException('Image acquisition failed')
Ejemplo n.º 4
0
	help="Set Exposure Time")
ap.add_argument("-min", "--minimum_thresh", type=int, default=50,
	help="minimum thresh value")
ap.add_argument("-max", "--maximum_thresh", type=int, default=255,
	help="maximum thresh value")
args = vars(ap.parse_args())

maxCamerasToUse = 2

# Get the transport layer factory.
tlFactory = pylon.TlFactory.GetInstance()

# Get all attached devices and exit application if no device is found.
devices = tlFactory.EnumerateDevices()
if len(devices) == 0:
    raise pylon.RuntimeException("No camera present.")

 # Create an array of instant cameras for the found devices and avoid exceeding a maximum number of devices.
cameras = pylon.InstantCameraArray(min(len(devices), maxCamerasToUse))

l = cameras.GetSize()

# Create and attach all Pylon Devices.
for i, cam in enumerate(cameras):
    cam.Attach(tlFactory.CreateDevice(devices[i]))

    # Print the model name of the camera.
    print("Using device ", cam.GetDeviceInfo().GetModelName())

# Grabing Continusely (video) with minimal delay
cameras.StartGrabbing()
Ejemplo n.º 5
0
    # Open the camera.
    camera.Open()

    # A GenICam node map is required for accessing chunk data. That's why a small node map is required for each grab result.
    # Creating a node map can be time consuming, because node maps are created by parsing an XML description file.
    # The node maps are usually created dynamically when StartGrabbing() is called.
    # To avoid a delay caused by node map creation in StartGrabbing() you have the option to create
    # a static pool of node maps once before grabbing.
    camera.StaticChunkNodeMapPoolSize = camera.MaxNumBuffer.GetValue()

    # Enable chunks in general.
    if genicam.IsWritable(camera.ChunkModeActive):
        camera.ChunkModeActive = True
    else:
        raise pylon.RuntimeException("The camera doesn't support chunk features")

    # Enable time stamp chunks.
    camera.ChunkSelector = "Timestamp"
    camera.ChunkEnable = True

    if not camera.IsUsb():
        # Enable frame counter chunks.
        camera.ChunkSelector = "Framecounter"
        camera.ChunkEnable = True

    # Enable CRC checksum chunks.
    camera.ChunkSelector = "PayloadCRC16"
    camera.ChunkEnable = True

    # Start the grabbing of c_countOfImagesToGrab images.
Ejemplo n.º 6
0
def test_2can():
    # Grab_MultipleCameras.cpp
    # ============================================================================
    # This sample illustrates how to grab and process images from multiple cameras
    # using the CInstantCameraArray class. The CInstantCameraArray class represents
    # an array of instant camera objects. It provides almost the same interface
    # as the instant camera for grabbing.
    # The main purpose of the CInstantCameraArray is to simplify waiting for images and
    # camera events of multiple cameras in one thread. This is done by providing a single
    # RetrieveResult method for all cameras in the array.
    # Alternatively, the grabbing can be started using the internal grab loop threads
    # of all cameras in the CInstantCameraArray. The grabbed images can then be processed by one or more
    # image event handlers. Please note that this is not shown in this example.
    # ============================================================================

    os.environ["PYLON_CAMEMU"] = "2"

    # Number of images to be grabbed.
    countOfImagesToGrab = 10 * 4

    # Limits the amount of cameras used for grabbing.
    # It is important to manage the available bandwidth when grabbing with multiple cameras.
    # This applies, for instance, if two GigE cameras are connected to the same network adapter via a switch.
    # To manage the bandwidth, the GevSCPD interpacket delay parameter and the GevSCFTD transmission delay
    # parameter can be set for each GigE camera device.
    # The "Controlling Packet Transmission Timing with the Interpacket and Frame Transmission Delays on Basler GigE Vision Cameras"
    # Application Notes (AW000649xx000)
    # provide more information about this topic.
    # The bandwidth used by a FireWire camera device can be limited by adjusting the packet size.
    maxCamerasToUse = 2

    # The exit code of the sample application.
    exitCode = 0

    try:

        # Get the transport layer factory.
        tlFactory = pylon.TlFactory.GetInstance()

        # Get all attached devices and exit application if no device is found.
        devices = tlFactory.EnumerateDevices()
        if len(devices) == 0:
            raise pylon.RuntimeException("No camera present.")

        # Create an array of instant cameras for the found devices and avoid exceeding a maximum number of devices.
        cameras = pylon.InstantCameraArray(min(len(devices), maxCamerasToUse))

        l = cameras.GetSize()

        # Create and attach all Pylon Devices.
        for i, cam in enumerate(cameras):
            cam.Attach(tlFactory.CreateDevice(devices[i]))

            # Print the model name of the camera.
            print("Using device ", cam.GetDeviceInfo().GetModelName())

        # Starts grabbing for all cameras starting with index 0. The grabbing
        # is started for one camera after the other. That's why the images of all
        # cameras are not taken at the same time.
        # However, a hardware trigger setup can be used to cause all cameras to grab images synchronously.
        # According to their default configuration, the cameras are
        # set up for free-running continuous acquisition.
        cameras.StartGrabbing()

        # Grab c_countOfImagesToGrab from the cameras.
        for i in range(countOfImagesToGrab):
            if not cameras.IsGrabbing():
                break

            grabResult = cameras.RetrieveResult(
                5000, pylon.TimeoutHandling_ThrowException)

            # When the cameras in the array are created the camera context value
            # is set to the index of the camera in the array.
            # The camera context is a user settable value.
            # This value is attached to each grab result and can be used
            # to determine the camera that produced the grab result.
            cameraContextValue = grabResult.GetCameraContext()

            # Print the index and the model name of the camera.
            print("Camera ", cameraContextValue, ": ",
                  cameras[cameraContextValue].GetDeviceInfo().GetModelName())

            # Now, the image data can be processed.
            print("GrabSucceeded: ", grabResult.GrabSucceeded())
            print("SizeX: ", grabResult.GetWidth())
            print("SizeY: ", grabResult.GetHeight())
            img = grabResult.GetArray()
            print("Gray value of first pixel: ", img[0, 0])

    except genicam.GenericException as e:
        # Error handling
        print("An exception occurred.", e.GetDescription())
        exitCode = 1

    # Comment the following two lines to disable waiting on exit.
    sys.exit(exitCode)