Community
cancel
Showing results for 
Search instead for 
Did you mean: 
MM_Leo
Beginner
121 Views

AccessViolation exception in using ippiErodeBorder_8u_C1R and ippiDilateBorder_8u_C1R

Hi,
 
I have started using ippiErodeBorder_8u_C1R and ippiDilateBorder_8u_C1R and I call these APIs in a loop ,however I get access violation exception during iteration.IPP2018 version is used here.Below is the code,can someone please point out the error?
The exception comes from ippiErodeBorder_8u_C1R
 
 
 
                int iSpecSize;
                int iBufferSize;
                imageSize = 416 x 416
                kernelSize = 3x3
                ippResult = ippcv_l.ippiMorphologyBorderGetSize_8u_C1R(imageSize, kernelSize, &iSpecSize, &iBufferSize);
 
                iSpecSize = 137
                iBufferSize = 2640
                nBytesPerImageLine = 1664
                offsetBinaryMaskWithBorder = 420
                imageSizeWithBorder.width = 419
                pKernelMask = byte[3,3] all filled with 1
 
             byte[,] pImageAsBinaryMask = new byte[416,416];
             byte[,] pImageAsBinaryMaskWithBorder = new byte[419,419];
 
 
                ipcvMorphState* pSpec = (ipcvMorphState*)ipps.ippsMalloc_8u(iSpecSize);
                byte* pBuffer = ipps.ippsMalloc_8u(iBufferSize);
 
                ippResult = ippcv_l.ippiMorphologyBorderInit_8u_C1R(imageSize, pKernelMask, kernelSize, pSpec, pBuffer);
                // Apply erosion filter
                ippResult = ippcv_l.ippiErodeBorder_8u_C1R(pImageAsBinaryMask, nBytesPerImageLine, pImageAsBinaryMaskWithBorder + offsetBinaryMaskWithBorder,imageSizeWithBorder.width * sizeof(float),
                    imageSize,IppiBorderType.ippBorderRepl, 0, pSpec, pBuffer);
 
 
                ippResult = ippcv_l.ippiDilateBorder_8u_C1R(pImageAsBinaryMask, nBytesPerImageLine, pImageAsBinaryMaskWithBorder + offsetBinaryMaskWithBorder, imageSizeWithBorder.width * sizeof(float),
                    imageSize, IppiBorderType.ippBorderRepl, 0, pSpec, pBuffer);
 
                ipps.ippsFree(pBuffer);
                ipps.ippsFree(pSpec);
 
Regards,
Leo
0 Kudos
2 Replies
Andrey_B_Intel
Employee
121 Views

Hi Leo.

Looks like that output image in your code is bigger than input. Input 416x416 and output is 419x419. It is non-standart situation but it is not a problem because you provide correct 'imageSize' to function. But step  'imageSizeWithBorder.width * sizeof(float)' is too big that causes crash. Please mul by sizeof(Ipp8u) or malloc 4x time more image.

I've redesigned your code with correct steps and pSpec.

#include "ipp.h"
#include "ippcv.h"
void main()
{
    int iSpecSize;
    int iBufferSize;
    IppiSize imageSize = { 416, 416 };
    IppiSize kernelSize = { 3, 3 };
    IppStatus ippResult;
    ippResult = ippiMorphologyBorderGetSize_8u_C1R(imageSize, kernelSize, &iSpecSize, &iBufferSize);
    int nBytesPerImageLine = 416;
    int offsetBinaryMaskWithBorder = 420;
    IppiSize imageSizeWithBorder = { 419, 419 };
    Ipp8u pKernelMask[3 * 3] = { 1, 1, 1, 1, 1, 1, 1, 1, 1 };
    Ipp8u* pImageAsBinaryMask           ;
    Ipp8u* pImageAsBinaryMaskWithBorder ;
    pImageAsBinaryMask = ippsMalloc_8u(416 * 416);
    pImageAsBinaryMaskWithBorder = ippsMalloc_8u(419 * 419);

    IppiMorphState* pSpec = (IppiMorphState*)ippsMalloc_8u(iSpecSize);
    Ipp8u* pBuffer        = ippsMalloc_8u(iBufferSize);
    ippResult = ippiMorphologyBorderInit_8u_C1R(imageSize, pKernelMask, kernelSize, pSpec, pBuffer);

    ippResult = ippiErodeBorder_8u_C1R(pImageAsBinaryMask, nBytesPerImageLine,
        pImageAsBinaryMaskWithBorder + offsetBinaryMaskWithBorder, imageSizeWithBorder.width * sizeof(Ipp8u),
        imageSize, ippBorderRepl, 0, pSpec, pBuffer);
    ippResult = ippiDilateBorder_8u_C1R(pImageAsBinaryMask, nBytesPerImageLine, pImageAsBinaryMaskWithBorder + offsetBinaryMaskWithBorder, imageSizeWithBorder.width * sizeof(Ipp8u),
        imageSize, ippBorderRepl, 0, pSpec, pBuffer);
    ippsFree(pBuffer);
    ippsFree(pSpec);
}

Thanks for using IPP library.

 

MM_Leo
Beginner
121 Views

Thanks ,that worked. Regards, Leo
Reply