-1

I am trying to replace my opencv resize() function with the Integrated Performance Primitives (IPP) API .
I am using IPP 7.1 version.
But After doing the below replacement I am not getting resized width and height .

Here is OpenCV function :

   Mat src,dest;    
   resize(src, dest, Size(cvRound(8.0 * src.cols/ width), cvRound(8.0 * src.rows / height)), INTER_LINEAR );
   //dest rows and cols are getting updated

Here is IPP function :

    IppiSize srcsize,dstsize;
    IppiPoint zoomedOffset = {0, 0};
    Ipp32s zoomOpSpecSize = 0, zoomOpInitSize = 0, zoomOpBufSize = 0;
    Ipp8u * zoomOpBuf = NULL;
    IppiResizeSpec_32f * zoomOpSpec = NULL;

    srcsize.height = src.rows;
    srcsize.width = src.cols;

    dstsize.height = dest.rows;
    dstsize.width = dest.cols;

    ippiResizeGetSize_8u(srcsize,dstsize,ippLinear, 0, &zoomOpSpecSize, &zoomOpInitSize);
    zoomOpSpec = (IppiResizeSpec_32f *)ippsMalloc_8u(zoomOpSpecSize);

    ippiResizeLinearInit_8u(srcsize, dstsize,zoomOpSpec);

    ippiResizeGetBufferSize_8u(zoomOpSpec, dstsize, 1, &zoomOpBufSize);
    zoomOpBuf = ippsMalloc_8u(zoomOpBufSize);

    ippiResizeLinear_8u_C1R(src.data,
                            src.cols,
                            dest.data,
                            dest.cols,
                            zoomedOffset,
                            dstsize,
                            ippBorderRepl,
                            0,
                            zoomOpSpec,
                            zoomOpBuf
                            );

   ippsFree(zoomOpSpec);
   ippsFree(zoomOpBuf);
Ashwin
  • 411
  • 1
  • 10
  • 28

2 Answers2

0

I have replaced the opencv call with the ipp call and got good result in terms of timing : Below is the changes I did in my code to achieve this :

IppiSize srcsize,dstsize;
    Ipp32s zoomOpSpecSize = 0, zoomOpInitSize = 0, zoomOpBufSize = 0;
    Ipp8u * zoomOpBuf = NULL;
    IppiResizeSpec_32f * zoomOpSpec = NULL;
    IppStatus status = ippStsNoErr;
    Ipp8u *pSrcT, *pDstT;

    IppiPoint srcOffset = {0, 0};
    IppiPoint dstOffset = {0, 0};

    srcsize.height = src.rows;
    srcsize.width = src.cols;
    dstsize = (IppiSize&)Size(cvRound(8.0 * iw / width), cvRound(8.0 * ih / height));

    dest.rows = dstsize.height;
    dest.cols = dstsize.width;

    /* Spec and init buffer sizes */
    status = ippiResizeGetSize_8u(srcsize,dstsize,ippLinear, 0, &zoomOpSpecSize, &zoomOpInitSize);

    /* Memory allocation */
    zoomOpSpec = (IppiResizeSpec_32f *)ippsMalloc_8u(zoomOpSpecSize);


    /* Filter initialization */
    status =ippiResizeLinearInit_8u(srcsize, dstsize,zoomOpSpec);


    ippiResizeGetBufferSize_8u(zoomOpSpec, dstsize, 3, &zoomOpBufSize);
    zoomOpBuf = ippsMalloc_8u(zoomOpBufSize);
    dest.data = ippsMalloc_8u(dest.rows * dest.cols * 3);
    //dstOffset.y  = dstOffset.y + dstsize.height;
    pSrcT = (Ipp8u*)((char*)src.data + srcOffset.y * src.step);
    pDstT = (Ipp8u*)((char*)dest.data + dstOffset.y * dest.step);

    dest.datastart = pDstT;
    dest.dataend = pDstT + (dest.rows *dest.cols*3);
    dest.datalimit = dest.dataend;

    status = ippiResizeLinear_8u_C3R(pSrcT,
                            src.step,
                            pDstT,
                            dest.cols * 3,
                            dstOffset,                          
                            dstsize,
                            ippBorderRepl,
                            0,
                            zoomOpSpec,
                            zoomOpBuf
                            );
   ippsFree(zoomOpSpec);
   ippsFree(zoomOpBuf); 
Ashwin
  • 411
  • 1
  • 10
  • 28
-1

Why are you doing it? OpenCV functions already include IPP functions, when enabled with CMake. The goal of OpenCV is to keep the final code clean, but you are going in the opposite way.

Avoid using IPP if the goal is to resize your image. Just stick with OpenCV's version. Simple, clean, efficient (thanks to IPP too)

madduci
  • 2,635
  • 1
  • 32
  • 51
  • Thanks blackibiza for your answer .Can you tell me mentioned IPP implementation for the openCV resize() function is correct ??If yes then Why I am not getting the required output?? – Ashwin Nov 04 '14 at 10:16
  • Hi Blackibiza,I did not find the ipp call inside opencv resize () function call !! – Ashwin Nov 05 '14 at 08:51
  • please refer to this other Stackoverflow thread: http://stackoverflow.com/questions/13465914/using-opencv-mat-images-with-intel-ipp – madduci Nov 06 '14 at 09:30
  • ,I am in doing now third level of optimization in my code ..I have seen this resize() opencv function as hot spot as compared to the other function . – Ashwin Nov 07 '14 at 07:01