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

  • DriveWorks SDK Reference
    5.20.37 Release
    For Test and Development only

    All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
    Image Creation and Conversion

    This section demonstrates the different methods to create an Image.

    Once an image is created, you can stream it from host (CPU) memory to device (CUDA) memory across:

    Creating an Image

    Basic Creation

    This is the simplest method to create an image.
    The ownership for the image is transferred to the application, which is responsible for destroying the object when no longer needed.

    dwImageProperties imageProperties{};
    imageProperties.type = DW_IMAGE_CPU;
    imageProperties.format = DW_IMAGE_FORMAT_RGB_UINT8_PLANAR;
    imageProperties.width = 1200;
    imageProperties.height = 800;
    dwImage_create(&image, imageProperties, ...);
    // CODE: Use image
    dwSomeDriveWorksModule_compute(image,...);
    dwImageType type
    Specifies the type of image.
    Definition: Image.h:497
    struct dwImageObject * dwImageHandle_t
    Definition: Image.h:105
    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.
    DW_API_PUBLIC dwStatus dwImage_destroy(dwImageHandle_t const image)
    Destroys the image handle and frees any memory created by dwImage_create().
    @ DW_IMAGE_CPU
    Definition: Image.h:97
    @ DW_IMAGE_FORMAT_RGB_UINT8_PLANAR
    Not backed by NvSci.
    Definition: Image.h:165
    Defines the properties of the image.
    Definition: Image.h:495

    Creation with Provided Buffer

    This method is similar to the Basic Creation. In this case, the application provides the memory buffer used to store the image.

    uint8_t* buffer[3];
    // CODE: Read some data source into buffer
    size_t* pitch[3];
    // CODE: Calculate pitch
    dwImageProperties imageProperties{};
    imageProperties.type = DW_IMAGE_CPU;
    imageProperties.format = DW_IMAGE_FORMAT_RGB_UINT8_PLANAR;
    imageProperties.width = 1200;
    imageProperties.height = 800;
    dwImage_createAndBindBuffer(&image, imageProperties, buffer, pitch, ...);
    // CODE: Use image
    dwSomeDriveWorksModule_compute(image,...); // NOTE, buffer might be modified here
    // Destroy the image handle
    // Note, the user provided buffer is still available for usage
    DW_API_PUBLIC dwStatus dwImage_createAndBindBuffer(dwImageHandle_t *const image, dwImageProperties properties, void *const buffersIn[DW_MAX_IMAGE_PLANES], size_t const pitches[DW_MAX_IMAGE_PLANES], size_t const bufferCount, dwContextHandle_t const ctx)
    Creates a dwImageHandle_t based on the properties passed and binds a memory buffer provided by the ap...

    Accessing Data Explicitly

    After creating an image through the demonstrated methods above, its content can be accessed in the following way:

    dwImageCPU *imageCPU;
    dwImage_getCPU(&imageCPU, image);
    size_t planeCount;
    for (uint32_t plane = 0; plane < planeCount; ++p) {
    for (uint32_t i = 0; i < imageProperties.height; ++i) {
    for (uint32_t j = 0; j < imageProperties.width; ++j) {
    imageCPU->data[plane][i * imageCPU->pitch[plane] + j] = ...; // this affects the image
    }
    }
    }
    size_t pitch[DW_MAX_IMAGE_PLANES]
    Specifies the pitch of the image in bytes.
    Definition: Image.h:516
    uint8_t * data[DW_MAX_IMAGE_PLANES]
    Specifies the raw image data.
    Definition: Image.h:518
    DW_API_PUBLIC dwStatus dwImage_getPlaneCount(size_t *const planeCount, dwImageFormat const format)
    Retrieves number of planes of the image format.
    DW_API_PUBLIC dwStatus dwImage_getCPU(dwImageCPU **const imageCPU, dwImageHandle_t const image)
    Retrieves the dwImageCPU of a dwImageHandle_t.
    Defines a CPU-based image.
    Definition: Image.h:512
    Note
    This snippet assumes the type of the image created is DW_IMAGE_CPU.

    Converting Format

    An image's format and properties can be converted in the following way:

    dwImageProperties imageProperties{};
    imageProperties.type = DW_IMAGE_CUDA;
    imageProperties.format = DW_IMAGE_FORMAT_RGBA_UINT8;
    imageProperties.width = 1200;
    imageProperties.height = 800;
    dwImageHandle_t outputImage;
    dwImage_create(&outputImage, imageProperties, ...);
    // CODE: Get some CUDA image
    dwImageHandle_t inputImage
    dwSomeDriveWorksModule_getImage(inputImage,...);
    dwImage_copyConvert(outputImage, inputImage,...);
    // CODE: Use outputImage
    ...
    // Destroy the outputing image
    dwImage_destroy(&outputImage);
    DW_API_PUBLIC dwStatus dwImage_copyConvert(dwImageHandle_t const output, dwConstImageHandle_t const input, dwContextHandle_t const context)
    Converts CUDA or NvMedia images by copying into an output image, following the properties in the outp...
    @ DW_IMAGE_CUDA
    Definition: Image.h:98
    @ DW_IMAGE_FORMAT_RGBA_UINT8
    Definition: Image.h:151
    Note
    The input and output images must be of the same type.
    This operation applies to DW_IMAGE_CUDA and DW_IMAGE_NVMEDIA only.
    人人超碰97caoporen国产