BaslerCamera Class

class basler.basler_camera.BaslerCamera(ip: str = None, serial_number: str = None)

A generic class for connecting Basler cameras and capturing images.

__init__(ip: str = None, serial_number: str = None)

The constructor looks for the camera by IP address or serial number (or both). If neither is specified, the first device is created.

Parameters
  • ip – IP address

  • serial_number – serial number

get_aoi()

return the area of interest (AOI) of the camera

Returns

a tuple: (offset_x, offset_y, width, height)

get_camera_info()

return a dictionary of a few properties of the camera, including Address, DeviceClass, DeviceID, FriendlyName, FullName, IpAddress, ModelName, SerialNumber

get_dynamic_range()

return the dynamic range of the image (affected by image format)

Returns

a tuple: (min_value, max_value)

get_exposure_time()

get the exposure time in millisecond (ms)

get_resulting_framerate()

get the resulting frame rate. If frame rate control is not enabled, return None

grab_many(n: int)

grab n frames and return a numpy array of shape (n, height, width)

Parameters

n – the number of frames

grab_n_save(n: int, save_pattern: str, n_start: int = 1)

grab n frames and save them sequentially as TIFF files according to save_pattern.

Parameters
  • n – the number of frames to grab

  • save_pattern – a string that contains one single ‘%d’ as the number. For Windows: r'D:\20200212Z\002\002-%d.tiff' (Don’t miss the leading ‘r’ which stands for ‘raw’ string; alternatively, use double backslash, e.g. 'D:\\20200212Z\\002\\002-%d.tiff') For Linux: '/home/zheli/002/002-%d.tiff'

  • n_start – the starting number or the sequence; default is 1

Example:

grab_n_save(200, '/home/zheli/images/0722-%d.tiff')

Images are saved as 0722-1.tiff, 0722-2.tif, …

grab_one()

grab one frame and return data as a numpy array

set_acquisition_framerate(framerate: float = None)

set the acquisition frame rate for the camera.

Parameters

framerate – acquisition framerate

The resulting (i.e. actural) framerate depends on a number of factors (see the official Basler Documentation) and may not equal the “acquisition frame rate” here.

static set_acquisition_framerate_helper(cam, framerate: float = None)

A helper method for set_acquisition_framerate

This method will attempt to change AcquisitionFrameRate property and then AcquisitionFrameRateAbs (as the property name varies from camera to camera). If no property is found, this method throws an error. If framerate is not specified or None, framerate control will be disabled.

set_aoi(aoi: tuple)

set the area of interest (AOI) of the camera.

Parameters

aoi – a tuple: (offset_x, offset_y, width, height)

set_converter(convert=True)

when saving TIFF files, always use a 16-bit format with the most significant bit (MSB) aligned.

Parameters

convert – a boolean

set_exposure_time(exposure_time: float)

set exposure time for the camera.

Parameters

exposure_time – the exposure time, with unit in millisecond (ms).

static set_exposure_time_helper(cam, exposure_time: float)

A helper method for set_exposure_time

This method will attempt to change ExposureTime property and then ExposureTimeAbs (as the property name varies from camera to camera). If no property is found, this method throws an error.

set_pixel_format(pixel_format_string: str)

set acquisition pixel format for the camera.

Parameters

pixel_format_string – a pixel format string, like Mono8, Mono12, Mono12Packed. Allowed values vary from camera to camera. Refer to camera documentation in the Pylon software for details.

exception basler.basler_camera.DeviceError