Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.

Intel IPP PCA RGB Image Subtraction

gargankit28
Beginner
1,207 Views
Hi,
I am developing a motion tracking application on an IPAQ H3970 with Windows CE. The camera that I am using for the application is LifeView FlyCAM-CF (350k).
When I subtract one RGB image from another using the ippiSub_8u_C3RSfs function, the resultant image is divided into 3. That is I can see the same subtracted image three times in the same video frame. Even when I save the resultant image as a bitmap file, it still shows as three.
Below is a snippet of my code. Please suggest a way to rectify this.
Thank you.
Ankit Garg
//Global variables
intg_prexsize=160;
intg_preysize=120;
intg_Capxsize=320;
intg_Capysize=240;
//Structure Definition Used
struct RGB_Struct
{
short width;
short height;
UINT8 *rgb;
};
//The function below takes two consecutive captures from the video and subtracts them
RGB_Struct *RGB1Temp, *RGB2Temp, *RGB3Temp;
RGB_Struct *g_pRGB2Out, *g_pRGB2Temp, *g_pRGB1Out, *g_pRGB1Temp;
unsigned char *pRGB1Temp, *pg_pRGB1Temp, *pRGB2Temp, *pg_pRGB2Temp;

SetCursor(LoadCursor(NULL, IDC_WAIT));
PreviewStop(hWnd);
g_pRGB1Out = (RGB_Struct *) AllocFileRGB(g_Capxsize, g_Capysize);
g_pRGB1Temp = (RGB_Struct *) AllocFileRGB( g_Capysize,g_Capxsize);
RGB1Temp = (RGB_Struct *) AllocFileRGB( g_Capysize,g_Capxsize);
PlaySound(L"\Program Files\FlyCAM-CF Tools\CAMERA.WAV", NULL, SND_SYNC);
Capture_A_Frame((unsigned char *)g_pRGB1Out->rgb, &dSize);
ShowRGB(hWnd, g_pRGB1Out);
Sleep(1000);
pRGB1Temp=RGB1Temp->rgb;
for(y=g_Capxsize-1;y>=0;y--)
{
pg_pRGB1Temp=g_pRGB1Temp->rgb+y*g_Capysize*3;
for(x=0;x{
*pRGB1Temp++=*pg_pRGB1Temp++;
*pRGB1Temp++=*pg_pRGB1Temp++;
*pRGB1Temp++=*pg_pRGB1Temp++;
}
}

const Ipp8u *pSrc1 = (Ipp8u *)(g_pRGB1Out->rgb);
int src1Step = 720;
IppiSize roiSize = {240, 320};

SetCursor(NULL);
PreviewStart2(hWnd);
SetCursor(LoadCursor(NULL, IDC_WAIT));
PreviewStop(hWnd);
g_pRGB2Out = (RGB_Struct *) AllocFileRGB(g_Capxsize, g_Capysize);
g_pRGB2Temp = (RGB_Struct *) AllocFileRGB( g_Capysize,g_Capxsize);
RGB2Temp = (RGB_Struct *) AllocFileRGB( g_Capysize,g_Capxsize);
RGB3Temp = (RGB_Struct *) AllocFileRGB( g_Capysize,g_Capxsize);

PlaySound(L"\Program Files\FlyCAM-CF Tools\CAMERA.WAV", NULL, SND_SYNC);
Capture_A_Frame((unsigned char *)g_pRGB2Out->rgb, &dSize);
pRGB2Temp=RGB2Temp->rgb;
for(y=g_Capxsize-1;y>=0;y--)
{
pg_pRGB2Temp=g_pRGB2Temp->rgb+y*g_Capysize*3;
for(x=0;x{
*pRGB2Temp++=*pg_pRGB2Temp++;
*pRGB2Temp++=*pg_pRGB2Temp++;
*pRGB2Temp++=*pg_pRGB2Temp++;
}
}

ShowRGB(hWnd, g_pRGB2Out);
Sleep(2000);
< DIV>
const Ipp8u *pSrc2 = (const Ipp8u*)(g_pRGB2Out->rgb);
//Ipp8u *pDst;
Ipp8u *pDst = (Ipp8u*)(RGB3Temp->rgb);
int src2Step = 720;
int dstStep = 720;
int scaleFactor = 1;
// Subtracts the 2 images here
ippiSub_8u_C3RSfs(pSrc1, src1Step, pSrc2, src2Step, pDst, dstStep, roiSize, scaleFactor);
// The subtracted image is displayed below as 3 copies in a frame
ShowRGB(hWnd, RGB3Temp);
Sleep(5000);

SetCursor(NULL);
FreeFileRGB(RGB1Temp);
FreeFileRGB(RGB2Temp);
FreeFileRGB(RGB3Temp);
FreeFileRGB(g_pRGB1Out);
FreeFileRGB(g_pRGB1Temp);
FreeFileRGB(g_pRGB2Out);
FreeFileRGB(g_pRGB2Temp);
PreviewStart(hWnd);


// Displays the image to the screen
BOOL ShowRGB (HWND hWnd, RGB_Struct *pRGB)
{
HDC hDC, hDCMem;
HGDIOBJ hOldObject;
HBITMAP hBitmap;
if (!pRGB->rgb || pRGB->width<=0 || pRGB->height<=0)
return FALSE;
/*
if ( (g_prexsize==160) && (g_preysize==120) )
{
// o Device Context
if (!(hDC=GetDC(hWnd)))
return FALSE;
}
else
{
// o Device Context
if (!(hDC=GetDC(NULL)))
return FALSE;
}
*/
// o Device Context
if (!(hDC=GetDC(hWnd)))
return FALSE;
// compatible DC
hDCMem = CreateCompatibleDC(hDC);
if (!hDCMem)
return FALSE;
// bitmap handle
if ((hBitmap = CreateBitmap(pRGB->width, pRGB->height, 1, 24, pRGB->rgb)) == NULL)
{
g_MainWindowInactiveDoNotClose=TRUE;
MessageBox( NULL, TEXT("CreateBitmap ERROR!"), NULL, NULL);
g_MainWindowInactiveDoNotClose=FALSE;
return FALSE;
}
// select object
if ((hOldObject=SelectObject(hDCMem, hBitmap)) == NULL)
{
g_MainWindowInactiveDoNotClose=TRUE;
MessageBox( NULL, TEXT("SelectObject ERROR!"), NULL, NULL);
g_MainWindowInactiveDoNotClose=FALSE;
return FALSE;
}
if (!BitBlt(hDC, g_preysize==120 ? 60 : 0 ,
g_preysize==120 ? 5: 0 ,
pRGB->width, pRGB->height, hDCMem, 0, 0, SRCCOPY)) //SRCCOPY
return FALSE;
SelectObject(hDCMem,hOldObject);
DeleteObject(hBitmap);
DeleteDC(hDCMem);
ReleaseDC (hWnd, hDC);
return TRUE;
}
//Fills up the RGB_Struct
VOID *AllocFileRGB(short width, short height)
{
RGB_Struct *pRGB;

pRGB = new RGB_Struct;
pRGB->width = width;
pRGB->height = height;
pRGB->rgb = (UINT8 *) malloc(width*height*3 * sizeof(UINT8));
return (RGB_Struct *) pRGB;
}
//Frees the memory allocated to RGB_Struct
void FreeFileRGB(RGB_Struct *pRGB)
{
if (pRGB->rgb)
{
free((void *) pRGB->rgb);
pRGB->rgb = NULL;
}
if (pRGB)
{
free((void *) pRGB);
pRGB = NULL;
}
}
0 Kudos
1 Reply
Ying_S_Intel
Employee
1,207 Views
Dear Customer,
Could you please submit this issue through our Intel Premier Support at https://premier.intel.com and our support engineer will look into your issue?

Thanks,
Ying
Intel IPP
0 Kudos
Reply