Loading [MathJax]/extensions/tex2jax.js
  • <xmp id="om0om">
  • <table id="om0om"><noscript id="om0om"></noscript></table>

  • DriveWorks SDK Reference
    5.10.90 Release
    For Test and Development only

    All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
    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:83
    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

    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.

    To create an image for where the output should be copied:

    dwImageProperties imgProperties{};
    dwRectifier_appendAllocationAttributes(&imgProperties, rectifier);
    // create images used by camera (output) and image rectifier
    dwImageHandle_t inputImage = nullptr; // the input image is got from the camera sensors.
    dwImageHandle_t rectifiedImage = nullptr;
    dwImage_create(&rectifiedImage, imgProperties, context);
    DW_API_PUBLIC dwStatus dwSensorCamera_appendAllocationAttributes(dwImageProperties *const imgProps, dwCameraOutputType const outputType, dwSensorHandle_t const sensor)
    Append the allocation attribute such that images allocated by the application and given to the camera...
    DW_API_PUBLIC dwStatus dwSensorCamera_getImageProperties(dwImageProperties *const imageProperties, dwCameraOutputType const outputType, dwSensorHandle_t const sensor)
    Gets information about the image properties for a given 'dwCameraImageOutputType'.
    @ DW_CAMERA_OUTPUT_NATIVE_PROCESSED
    processed images (usually be YUV420 planar or RGB planar)
    Definition: Camera.h:80
    struct dwImageObject * dwImageHandle_t
    Definition: Image.h:102
    DW_API_PUBLIC dwStatus dwImage_create(dwImageHandle_t *const image, dwImageProperties properties, dwContextHandle_t const ctx)
    Creates and allocates resources for a dwImageHandle_t based on the properties passed as input.
    Defines the properties of the image.
    Definition: Image.h:390
    DW_API_PUBLIC dwStatus dwRectifier_appendAllocationAttributes(dwImageProperties *const imgProps, dwRectifierHandle_t obj)
    Append the allocation attribute such that the images created of type DW_IMAGE_NVMEDIA can be fed to d...

    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.

    人人超碰97caoporen国产