There's a clean way to pass OpenCV data into an IPP function.
If we have an OpenCV Mat
, we can cast *Mat.data[0]
to an const Ipp<type>*
. For example, if we're dealing with 8-bit unsigned char (8u
) data, we can plug (const Ipp8u*)&img.data[0]
into an IPP function. Here's an example using the ippiFilter
function with the typical Lena image:
Mat img = imread("./Lena.pgm"); //OpenCV 8U_C1 image
Mat outImg = img.clone(); //allocate space for convolution results
int step = img.cols; //pitch
const Ipp32s kernel[9] = {-1, 0, 1, -1, 0, 1, -1, 0, 1};
IppiSize kernelSize = {3,3};
IppiSize dstRoiSize = {img.cols - kernelSize.width + 1, img.rows - kernelSize.height + 1};
IppiPoint anchor = {2,2};
int divisor = 1;
IppStatus status = ippiFilter_8u_C1R((const Ipp8u*)&img.data[0], step,
(Ipp8u*)&outImg.data[0], step, dstRoiSize,
kernel, kernelSize, anchor, divisor);
When I write outImg
(from the above code) to a file, it gives the expected result:
This matches the result I got when I ran the Nvidia version, nppiFilter
, with the same parameters:
I mentioned a structure called CIppiImage
in the original question. CIppiImage
just a simple wrapper for an array.