Python camera_info_manager interface, providing CameraInfo support for drivers written in Python. This is very similar to the C++ camera_info_manager package, but not identical.
..exception: CameraInfoError
Base class for exceptions in this module.
..exception: CameraInfoMissingError
Exception raised when CameraInfo has not been loaded.
CameraInfoManager provides ROS CameraInfo support for Python camera drivers. It handles the sensor_msgs/SetCameraInfo service requests, saving and restoring sensor_msgs/CameraInfo data.
Parameters: |
|
---|
Returns: | String representation of CameraInfoManager object. |
---|
ROS Service
calibration information
Typically, these service requests are made by a calibration package, such as:
The calling node must invoke rospy.spin() in some thread, so CameraInfoManager gets called to handle arriving service requests.
If a driver handles multiple cameras, it should use the namespace parameter to declare separate CameraInfoManager instances for each one, as in this stereo example:
left_ci = CameraInfoManager(cname='left_camera', namespace='left')
right_ci = CameraInfoManager(cname='right_camera', namespace='right')
Camera Name
The device driver sets a camera name via the CameraInfoManager constructor or the setCameraName() method. This name is written when CameraInfo is saved, and checked when data are loaded, with a warning logged if the name read does not match.
Camera drivers may use any syntactically valid name they please. Where possible, it is best for the name to be unique to the device, such as a GUID, or the make, model and serial number. Any parameters that affect calibration, such as resolution, focus, zoom, etc., may also be included in the name, uniquely identifying each CameraInfo file.
The camera name can be resolved as part of the URL, allowing direct access to device-specific calibration information.
Uniform Resource Locator
The location for getting and saving calibration data is expressed by Uniform Resource Locator. The driver defines a URL via the CameraInfoManager constructor or the setURL() method. Many drivers provide a ~camera_info_url parameter so users may customize this URL, but that is handled outside this class.
Camera calibration information is stored in YAML format.
Example URL syntax:
The file: URL specifies a full path name in the local system. The package: URL is handled the same as file:, except the path name is resolved relative to the location of the named ROS package, which must be reachable via $ROS_PACKAGE_PATH.
The URL may contain substitution variables delimited by ${...}, including:
device driver.
defined, ~/.ros if not.
Resolution is done in a single pass through the URL string. Variable values containing substitutable strings are not resolved recursively. Unrecognized variable names are treated literally with no substitution, but an error is logged.
Examples with variable substitution:
The default URL is:
If that file exists, its contents are used. Any new calibration will be stored there, missing parent directories being created if necessary and possible.
Loading Calibration Data
Unlike the C++ camera_info_manager, this Python implementation loads nothing until the loadCameraInfo() method is called. It is an error to call getCameraInfo(), or isCalibrated() before that is done.
If the URL or camera name changes, loadCameraInfo() must be called again before the data are accessible.
Get the current camera calibration.
The loadCameraInfo() must have been called since the last time the camera name or URL changed.
Returns: | sensor_msgs/CameraInfo message. |
---|---|
Raises: | CameraInfoMissingError if camera info not up to date. |
Is the current CameraInfo calibrated?
The loadCameraInfo() must have been called since the last time the camera name or URL changed.
Returns: | True if camera calibration exists; False for null calibration. |
---|---|
Raises: | CameraInfoMissingError if camera info not up to date. |
Load currently configured calibration data (if any).
This method updates camera_info, if possible, based on the currently-configured URL and camera name. An empty or non-existent calibration is not considered an error; a null sensor_msgs/CameraInfo being provided in that case.
Raises: | IOError if an existing calibration is unreadable. |
---|
Callback for SetCameraInfo request.
Parameters: | req – SetCameraInfo request message. |
---|---|
Returns: | SetCameraInfo response message, success is True if message handled. |
Post: | camera_info updated, can be used immediately without reloading. |
Set a new camera name.
Parameters: | cname – camera name to use for saving calibration data |
---|---|
Returns: | True if new name has valid syntax; valid names contain only alphabetic, numeric, or ‘_’ characters. |
Post: | camera name updated, if valid. A new name may affect the URL, so camera_info will have to be reloaded before being used again. |
Generate a valid camera name.
Valid names contain only alphabetic, numeric, or ‘_’ characters. All invalid characters in from_string are replaced by an ‘_’.
Parameters: | from_string – string from which to base camera name. |
---|---|
Returns: | a valid camera name based on from_string. |
Get file name corresponding to a package: URL.
param url fully-resolved Uniform Resource Locator returns file name if package found, “” otherwise
Load calibration data from a file.
This function returns a sensor_msgs/CameraInfo message, based on the filename parameter. An empty or non-existent file is not considered an error; a null CameraInfo being provided in that case.
Parameters: |
|
---|---|
Returns: | sensor_msgs/CameraInfo message containing calibration, if file readable; null calibration message otherwise. |
Raises: | IOError if an existing calibration file is unreadable. |
Parse calibration Uniform Resource Locator.
param url: string to parse returns URL type code
note: Unsupported URL types have codes >= URL_invalid.
Resolve substitution strings in Uniform Resource Locator.
Parameters: |
|
---|---|
Returns: | a copy of the URL with any variable information resolved. |
Save calibration data.
This function writes new calibration information to the location defined by the url and cname parameters, if possible.
Parameters: |
|
---|---|
Returns: | True if able to save the data. |
Save calibration data to a YAML file.
This function writes the new calibration information to a YAML file, if possible.
Parameters: |
|
---|---|
Returns: | True if able to save the data. |