Community
cancel
Showing results for 
Search instead for 
Did you mean: 
tarifut
Beginner
123 Views

IPP+Opencv png overlay

Hello,

I can't find anything to help me to overlay a png file over a video using IPP and Opencv.
I use Opencv in order to read video frames but i can't load a png file with ipp and overlay over my frame with my transparent png (i want to use the png alpha layer)

Can someone help me?

thanks

0 Kudos
3 Replies
Ying_H_Intel
Employee
123 Views

Hello tarifut,

You may have known that IPP provide some image processing functions, like ippiAlphaComp_8u_C3R(), whichcomposite two image buffers using either the opacity (alpha) channel in the images or provided alpha values. These functions operate on image buffers with 8-bit or 16-bit data in RGB or RGBA format. In
all compositing operations a resultant pixel in destination buffer pDst is created by overlaying
a pixel from the foreground image buffer pSrc1 over a pixel from the background image buffer
pSrc2.

Pleasefind more functions from IPP manual ippiman.pdf under /Doc/.

Butallipp functionsassume the image has been loaded into system memory. So if you have load both frame and png file insome memory buffer, you can select approprate IPP function to complete the functionality.

Lucky, OpenCV shouldprovide such load functions, right? . It canread video frame and load a png fileto some memory buffer, then employ IPP function to do any operation you wanted to do.

For example,Iload a png file andcopyit into another image. I writec code as below.

#include "stdafx.h"
#include
#include
#include "ipp.h"
#include "cv.h"
#include "highgui.h"
#include
#include "string.h"

using namespace std;

#define COMP 3
int main()
{

//int nFuncs=cvUseOptimized(1);
// cout<< "number of function optimized is" << nFuncs << endl;
//const char* opencv_libraries = 0;
//const char* addon_modules = 0;
//cvGetModuleInfo(0, &opencv_libraries,&addon_modules );
//printf( "OpenCV: %s\nAdd-on Modules: %s\n",opencv_libraries, addon_modules );

IplImage* dst;
CvSize cvsrcSize;
CvSize cvdstSize;
IppStatus status;


IplImage* src = cvLoadImage( "pic1.png", 1 ); //"ring.bmp"pic1.png

cvsrcSize=cvGetSize(src);
int w= cvsrcSize.width;
int h= cvsrcSize.height;
IppiRect srcRect = { 0, 0,w, h };
IppiSize srcSize = {w, h };

CvSize cvsrcTempSize={w, h};
IppiSize srcTempSize={w, h};
IplImage* srcTemp = cvCreateImage ( cvsrcTempSize,8, COMP);
//Ipp8u backValue[4]={255,255,255,0};
ippiSet_8u_C3R (0, (Ipp8u*) srcTemp->imageData, srcTemp->widthStep, srcTempSize );


status=ippiCopy_8u_C3R( (Ipp8u*) src->imageData, src->widthStep,
(Ipp8u*) srcTemp->imageData,,
srcTemp->widthStep,
srcSize);
return 0;
}

Hope it helps and let us know if any problem on using IPP function.

Best Regards,
Ying

tarifut
Beginner
123 Views

Thanks for your help!!!
But i don't understand something, you speak aboutippiAlphaComp_8u_C3 there is no such function in the documentation :
Supported values for : 8u_AP4R 16u_AP4R
How can i use ippiAlphaComp?
Could you, please, show me how to load a png file with IPP, a jpg file (for exemple) with openCV, overlay png over jpg (with alpha transparency) and save the iamge with openCV?
Ying_H_Intel
Employee
123 Views

Hello Tarifut,

You may refer to the manual and make sure what parameter the function needed.

There is ippiAlphaCompC function call example code.

Example 5-7 Using Alpha Composition Function
IppStatus acomp( void ) {

Ipp8u imga[8*8], imgb[8*8], imgc[8*8];
IppiSize roi = { 8, 8 };
IppStatus st;
ippiImageRamp_8u_C1R( imga, 8, roi, 0, 1, ippAxsHorizontal );
ippiImageRamp_8u_C1R( imgb, 8, roi, 0, 2, ippAxsHorizontal );
st = ippiAlphaCompC_8u_C1R( imga, 8, 255/3, imgb, 8, 255, imgc, 8, roi, ippAlphaOver );
printf( "over: a=%d,A=255/3; b=%d,B=255; c=%d //
c=a*A+b*(1-A)*B\n",imga[6],imgb[6],imgc[6] );
return st;
}
Output
over: a=6,A=255/3; b=12,B=255; c=10 // c=a*A+b*B*(1-A)

IPP can't be used to load a file. what ever png or jpg.You may need to load them into memory bufferby openCV, then feed the correspoinding data pointer to ippiAlphaComp function.Sorry, we haven'tready opencv codefor you. Have you run into an exact question whencreate the code? (You may send me your code by private thread)

Regards,
Ying
Reply