DriveWorks SDK Reference
5.8.83 Release
For Test and Development only

Rectifier Workflow

This tutorial will show you how to convert images captured with a camera model into a different camera model.

In this example we'll use as input a camera from our rig configuration file:

dwInitialize(&contextHandle, DW_VERSION, &sdkParams)
dwRig_initializeFromFile(&rigConf, contextHandle, rigConfigFilename);
dwRig_findSensorByName(&sensorId, cameraName, rigConf)
dwCameraModel_initialize(&cameraModelIn, sensorId, rigConf)
#define DW_VERSION
struct dwCameraModelObject * dwCameraModelHandle_t
A pointer to the handle representing a calibrated camera model.
Definition: CameraModel.h:67
DW_API_PUBLIC dwStatus dwCameraModel_initialize(dwCameraModelHandle_t *camera, uint32_t sensorId, dwConstRigHandle_t obj)
Creates a calibrated camera model polymorphically for a compatible sensor.
DW_API_PUBLIC dwStatus dwInitialize(dwContextHandle_t *const context, dwVersion const headerVersion, dwContextParameters const *const params)
Creates and initializes an SDK context.
#define DW_NULL_HANDLE
Definition: Types.h:96
DW_API_PUBLIC dwStatus dwRig_findSensorByName(uint32_t *const sensorId, char8_t const *const sensorName, dwConstRigHandle_t const obj)
Finds the sensor with the given name and returns its index.
DW_API_PUBLIC dwStatus dwRig_initializeFromFile(dwRigHandle_t *const obj, dwContextHandle_t const ctx, char8_t const *const configurationFile)
Initializes the Rig Configuration module from a file.

The following two snippets demonstrate how to initialize different output camera models.
contextHandle is assumed to be previously initialized dwContextHandle_t.

Example of camera for rectification (undistortion)

// Settings
dwPinholeCameraConfig cameraConf = {};
cameraConf.distortion[0] = 0.f;
cameraConf.distortion[1] = 0.f;
cameraConf.distortion[2] = 0.f;
// CODE: other settings of camera
dwCameraModel_initializePinhole(&cameraModelOut, &cameraConf, contextHandle);
DW_API_PUBLIC dwStatus dwCameraModel_initializePinhole(dwCameraModelHandle_t *obj, const dwPinholeCameraConfig *config, dwContextHandle_t context)
Creates and initializes a calibrated pinhole camera.
float32_t distortion[DW_PINHOLE_DISTORTION_LENGTH]
Polynomial coefficients [k_1, k_2, k_3] that allow to map undistored, normalized image coordinates (x...
Definition: Rig.h:155
Configuration parameters for a calibrated pinhole camera.
Definition: Rig.h:132

Example of camera for model projection (simulation)

// CODE: create settings of simulated FTheta camera
dwCameraModel_initializeFTheta(&cameraModelOut, &cameraConf, contextHandle);
DW_API_PUBLIC dwStatus dwCameraModel_initializeFTheta(dwCameraModelHandle_t *obj, const dwFThetaCameraConfig *config, dwContextHandle_t context)
Creates and initializes a calibrated camera for the F-Theta distortion model.

Use of the rectifier

The rectifier module can be initialized with the camera models that we have just created:

dwRectifier_initialize(&rectifier, cameraModelIn, cameraModelOut, contextHandle);
DW_API_PUBLIC dwStatus dwRectifier_initialize(dwRectifierHandle_t *obj, dwCameraModelHandle_t cameraIn, dwCameraModelHandle_t cameraOut, dwContextHandle_t ctx)
Initializes a rectifier based on an input and output camera model and a homography.

And can be used on images coming from a live sensor or from a recording:

while(loop) {
// CODE: get image from camera, stream it (optional)
dwRectifier_setHomography(&homography, rectifier); //optional
dwRectifier_warp(&rectifiedImage, inputImage, rectifier);
}
DW_API_PUBLIC dwStatus dwRectifier_warp(dwImageCUDA *outputImage, const dwImageCUDA *inputImage, bool setOutsidePixelsToBlack, dwRectifierHandle_t obj)
Warps the image from the input camera model to the model of the output camera using CUDA on the GPU.
DW_API_PUBLIC dwStatus dwRectifier_setHomography(const dwMatrix3f *homography, dwRectifierHandle_t obj)
Sets the homography matrix used.

For simplicity, the actual sensor management, including retrieving images from a camera, is omitted in this tutorial.
For more information see Camera Workflow.

Finally all handles can be released:

dwCameraModel_release(cameraModelIn);
dwCameraModel_release(cameraModelOut);
dwRelease(contextHandle);
DW_API_PUBLIC dwStatus dwCameraModel_release(dwCameraModelHandle_t obj)
Releases the calibrated camera.
DW_API_PUBLIC dwStatus dwRelease(dwContextHandle_t const context)
Releases the context.
DW_API_PUBLIC dwStatus dwRectifier_release(dwRectifierHandle_t obj)
Releases the rectifier module.

For the full implementation refer to Video Rectification Sample.
See Rig Configuration for more information on Calibrated Cameras.