Hi, I have some problems width canny edge detector using IPP
I make three steps:
I have 3-channel image(byte array), that ordered like this RGBRGB...
The first step is applying grayScale filter.
The second is calculation gradients dx and dy using IPP vertical and horizontal Sobel filters with border,
The last step is using ippiCanny
Code:
unsigned char * RGBToGrayScaleIpp(unsigned char * src, int width, int height, int channels)
{
IppiSize ROI = {width, height};
Ipp8u *GrayScaleImg = new Ipp8u[width * height];
ippiRGBToGray_8u_C3C1R(src, width * channels * sizeof(Ipp8u), GrayScaleImg, width * sizeof(Ipp8u), ROI);
return GrayScaleImg;
}
extern "C" __declspec(dllexport) unsigned char* __stdcall Canny(unsigned char * img, int channels, int width, int height)
{
Ipp8u *GrayScaleImg = RGBToGrayScaleIpp(img, width, height, channels);
IppiSize roiSize = {width - 1, height - 1};
int horizBufferSize, vertBufferSize;
IppiMaskSize maskSize = ippMskSize3x3;
ippiFilterSobelVertGetBufferSize_8u16s_C1R(roiSize, maskSize, &vertBufferSize);
ippiFilterSobelHorizGetBufferSize_8u16s_C1R(roiSize, maskSize, &horizBufferSize);
Ipp8u *horizBuffer = ippsMalloc_8u(horizBufferSize);
Ipp8u *vertBuffer = ippsMalloc_8u(vertBufferSize);
Ipp16s *dx = new Ipp16s[width * height];
Ipp16s *dy = new Ipp16s[width * height];
ippiFilterSobelVertBorder_8u16s_C1R(GrayScaleImg, width * sizeof(Ipp8u), dx, (width - 1) * sizeof(Ipp16s), roiSize, maskSize, ippBorderRepl, 0, vertBuffer);
ippiFilterSobelHorizBorder_8u16s_C1R(GrayScaleImg, width * sizeof(Ipp8u), dy, (width - 1) * sizeof(Ipp16s), roiSize, maskSize, ippBorderRepl, 0, horizBuffer);
Ipp8u *buffer;
if (vertBufferSize < horizBufferSize)
{
ippiCannyGetSize(roiSize, &horizBufferSize);
buffer = ippsMalloc_8u(horizBufferSize);
}
else
{
ippiCannyGetSize(roiSize, &vertBufferSize);
buffer = ippsMalloc_8u(vertBufferSize);
}
Ipp32f low=100.0f, high=100.0f;
Ipp8u* dst = new Ipp8u[width * height];
ippiCanny_16s8u_C1R(dx, (width - 1) * sizeof(Ipp16s), dy, (width - 1) * sizeof(Ipp16s), dst, width * sizeof(Ipp8u), roiSize, low, high, buffer);
ippsFree(buffer);
return dst;
}
I get incorrect result. In attach files there are 3 images source, filtered using .NET Aforge and filtered using IPP. Can you see any mistakes in my code? Please, help.