Intel® Integrated Performance Primitives (Intel® IPP) Developer Guide and Reference

ID 790148
Date 3/22/2024
Public
Document Table of Contents

CreateMapCameraUndistort

Creates look-up tables of coordinates of corrected image.

Syntax

IppStatus ippiCreateMapCameraUndistort_32f_C1R(Ipp32f* pxMap, int xStep, Ipp32f* pyMap, int yStep, IppiSize roiSize, Ipp32f fx, Ipp32f fy, Ipp32f cx, Ipp32f cy, Ipp32f k1, Ipp32f k2, Ipp32f p1, Ipp32f p2, Ipp8u* pBuffer);

Include Files

ippcv.h

Domain Dependencies

Headers: ippcore.h, ippvm.h, ipps.h, ippi.h

Libraries: ippcore.lib, ippvm.lib, ipps.lib, ippi.lib

Parameters

pxMap
Pointer to the destination x coordinate look-up buffer.
xStep
Distance in bytes between starts of consecutive lines in the pxMap image.
pyMap
Pointer to the destination y coordinate look-up buffer.
yStep
Distance in bytes between starts of consecutive lines in the pyMap image.
roiSize
Size of source and destination images ROI in pixels.
fx
Focal lengths along the x axis.
fy
Focal lengths along the y axis.
cx
x-coordinate of the principal point.
cy
y-coordinate of the principal point.
k1
First coefficient of radial distortion.
k2
Second coefficient of radial distortion.
p1
First coefficient of tangential distortion.
p2
Second coefficient of tangential distortion.
pBuffer
Pointer to the external buffer.

Description

This function operates with ROI (see Regions of Interest in Intel IPP ).

This function creates the look-up tables of x- and y-coordinates pxMap and pyMap respectively. These coordinates are computed in accordance with camera parameters fx, fy, cx, cy, and distortion parameters k1, k2, p1, p2. The created tables can be used by the Intel IPP function ippiRemap to remap the distorted source image and get the corrected image.

To accelerate the computations the function can pass the pointer to the external buffer pBuffer whose size should be computed previously using the function ippiUndistortGetSize. If a null pointer is passed, slower computations without an external buffer will be performed.

Return Values

ippStsNoErr

Indicates no error.

ippStsNullPtrErr

Indicates an error if pxMap or pyMap is NULL.

ippStsSizeErr

Indicates an error condition if roiSize has a field with zero or negative value.

ippStsStepErr

Indicates an error condition if : xStep is less than roiSize.width * <pixelSize> , or yStep is less than roiSize.width * <pixelSize>.

ippStsNotEvenStepErr

Indicates an error condition if one of the step values is not divisible by 4 for floating-point images.

ippStsBadArgErr

Indicates an error when fx or fy is equal to 0.

Example

/*******************************************************************************
* Copyright 2015 Intel Corporation.
*
*
* This software and the related documents are Intel copyrighted materials, and your use of them is governed by
* the express license under which they were provided to you ('License'). Unless the License provides otherwise,
* you may not use, modify, copy, publish, distribute, disclose or transmit this software or the related
* documents without Intel's prior written permission.
* This software and the related documents are provided as is, with no express or implied warranties, other than
* those that are expressly stated in the License.
*******************************************************************************/

// A simple example of initialization of x and y maps for undistortion
// using Intel(R) Integrated Performance Primitives (Intel(R) IPP) functions:
//     ippiUndistortGetSize
//     ippiCreateMapCameraUndistort_32f_C1R
//     ippiRemap_32f_C1R

#include <stdio.h>
#include "ipp.h"

#define WIDTH  640 /* Source image width */
#define HEIGHT 480 /* Destination image width */

/* Next two defines are created to simplify code reading and understanding */
#define EXIT_MAIN exitLine:                                  /* Label for Exit */
#define check_sts(st) if((st) != ippStsNoErr) goto exitLine; /* Go to Exit if Intel(R) IPP function returned status different from ippStsNoErr */

/* Results of ippMalloc() are not validated because Intel(R) IPP functions perform bad arguments check and will return an appropriate status  */

int main(void)
{
    IppStatus status = ippStsNoErr;
    Ipp32f* pSrc = NULL, *pDst = NULL;    /* Pointers to source/destination images */
    int srcStep = 0, dstStep = 0;         /* Steps, in bytes, through the source/destination images */
    IppiSize roiSize = { WIDTH, HEIGHT }; /* Size of source/destination ROI in pixels */
    Ipp32f* pxMap = NULL, *pyMap = NULL;  /* Pointers to x and y maps */
    Ipp8u*  pBuffer = NULL;               /* Pointer to work buffer */
    int buflen = 0;
    int xStep = 0, yStep = 0;                   /* Steps, in bytes, through the x and y maps */
    IppiRect rect = { 0, 0, WIDTH, HEIGHT };    /* Region of interest in the source image */
    Ipp32f fx = WIDTH / 3.f, fy = HEIGHT / 2.f; /* Focal lengths */
    Ipp32f cx = WIDTH / 2.f, cy = HEIGHT / 2.f; /* Coordinates of principal point */
    Ipp32f k1 = 0.04f, k2 = 0.004f;             /* Coeffs of radial distortion */
    Ipp32f p1 = 0.02f, p2 = 0.02f;              /* Coeffs of tangential distortion */

    pSrc  = ippiMalloc_32f_C1(roiSize.width, roiSize.height, &srcStep);
    pDst  = ippiMalloc_32f_C1(roiSize.width, roiSize.height, &dstStep);
    pxMap = ippiMalloc_32f_C1(roiSize.width, roiSize.height, &xStep);
    pyMap = ippiMalloc_32f_C1(roiSize.width, roiSize.height, &yStep);

    check_sts( status = ippiSet_32f_C1R(0.1234567f, pSrc, srcStep, roiSize) )

    check_sts( status = ippiUndistortGetSize(roiSize, &buflen) )

    pBuffer = ippsMalloc_8u(buflen);

    /* Initialize x and y maps for undistortion by the ippiRemap function */
    check_sts( status = ippiCreateMapCameraUndistort_32f_C1R(pxMap, xStep, pyMap, yStep, roiSize,
        fx, fy, cx, cy, k1, k2, p1, p2, pBuffer) )

    /* Transform the source image by remapping its pixels */
    check_sts( status = ippiRemap_32f_C1R(pSrc, roiSize, srcStep, rect, pxMap, xStep, pyMap, yStep,
        pDst, dstStep, roiSize, IPPI_INTER_LINEAR) )

EXIT_MAIN
    ippiFree(pyMap);
    ippiFree(pxMap);
    ippsFree(pBuffer);
    ippiFree(pSrc);
    ippiFree(pDst);

    printf("Exit status %d (%s)\n", (int)status, ippGetStatusString(status));
    return (int)status;
}