Intel® Integrated Performance Primitives
Deliberate problems developing high-performance vision, signal, security, and storage applications.

newbie question about Remap

moduspwnens
Beginner
478 Views
I am just learning IPP and I also don't know very much about image processing yet, so this is probably a very basic question.
Anyway, I am using frei0r to call the IPP remap function. This function takes three inputs and has an output. Then, I call this function in gstreamer. However, gstreamer is saying I get a segfault in this code, and I don't know what I am doing wrong, although I am almost positive it has to do with the parameters I am supplying to remap. I'm pretty sure the problem is with the srcSize argument, because if I changed it to 0 it works. Anything else causes it to fail. However, I don't understand why that would happen..
Here is my function:
[bash]void f0r_update2(f0r_instance_t instance,
		 double time,
		 const uint32_t* inframe1,
		 const uint32_t* inframe2,
		 const uint32_t* inframe3,
		 uint32_t* outframe)
{
  assert(instance);
  composition_instance_t* inst = (composition_instance_t*)instance;
  unsigned int w = inst->width; //this is in pixels
  unsigned int h = inst->height; //this is in pixels

  unsigned char *ps1, *ps2, *pd, *pd_end;
  ps1 = (unsigned char *)inframe2;
  ps2 = (unsigned char *)inframe1;
  pd = (unsigned char *)outframe;
  pd_end = pd + ( w * h * 4 );
  IppiSize sz = {w, h};
  IppiRect rect = {0, 0, w*4, w*4};
  ippiRemap_8u_AC4R((const Ipp8u *) inframe1, sz, w*4, rect, (const Ipp32f *) inframe2, w*h, 
      (const Ipp32f *) inframe3, w*h, (Ipp8u *) outframe, w*4, sz, IPPI_INTER_NN); 
}[/bash]
0 Kudos
5 Replies
Ying_H_Intel
Employee
478 Views
Hello

The problem may be the parameter of ippiRemaps, especially this one
IppiRectrect={0,0,w*4,w*4};
itseems notw*4 and w*4. in general, if with the wholeimage, it should be {0, 0, w, h}, (AC4 mean 4channel, the memory layout are RGBA,RGBA,RGBA...).
and otherparameters, like w*4 may notcorrect too ifinput framehaspadded at image border.
and if inframe1, inframe2, inframe3 are same inputtype, may be have same width in bytes, additionally change inframe2, inframe3to 32f*, the stride is 4, so w*hmaynot correct too.

You may readthe article Descriptor Codes and Parameters for ippi Functions tocheck theseparamters and get correct result.

BestWishes,
Ying
0 Kudos
moduspwnens
Beginner
478 Views
Hmm, should the dimensions of IppiRect not be in bytes? w and h are in pixels.

Also, I can't change the function parameters, unfortunately as it is part of frei0r. However, I did something similar with the AlphaComp function so I know the casting works.

Since this is a part of frei0r, I also know for a fact that there is not image padding as frei0r is particular about that.
0 Kudos
Ying_H_Intel
Employee
478 Views

Hello m,

Yes, ippiRect is in pixel, not in bytes.

You mentioned, "I can't change the function parameters and However, I did something similar with the AlphaComp function so I know the casting works", Can you provide the details, like what is the inframe1 and inframe2, imframe3?

I attached one smallsample code for your reference, youmay try them andalign/modify all of parameters of ippiRemapwithyour external parameter.
for example,
constuint32_t*inframe1, // but the value in the memory space should be RGBARGBA
constuint32_t*inframe2,// the value in the memory space should be x-coordinates
constuint32_t*inframe3, // the value in the memory space should be y coordinates
You can cast them to IPP 8u* or IPP32f*, butthexMapStep, yMapStepseems not correct . why are they w*h, could be w*h*sizeof(Ipp32f)?

/ Image_Transpose.cpp: Transpose a image or rotate image with 90 or 270 degree

#include
#include
#include


#include "ipp.h"
int LOOP=1000;
using namespace std;


int main()
{

int SRC_WIDTH= 512;
int SRC_HEIGHT=512;

//Destination image size
int TARGET_WIDTH =SRC_HEIGHT;
int TARGET_HEIGHT =SRC_WIDTH;

//Create Map coordinate ( dst(x,y) = src( y,x), Rotate 90 degree)
int nTableSize= SRC_HEIGHT * SRC_WIDTH;
float* pXTable = (float*) malloc(sizeof(float)*nTableSize);
float* pYTable = (float*) malloc(sizeof(float)*nTableSize);

for( int iMap=0; iMapfor( int jMap=0; jMap< TARGET_WIDTH; jMap++ )
{
pXTable[iMap*TARGET_WIDTH+jMap] = iMap;
pYTable[iMap*TARGET_WIDTH+jMap] = jMap;
}

/* Performs image transpose by IPPRemap */

const IppLibraryVersion* lib = ippiGetLibVersion();
printf(" IPP version:%s %s %d.%d.%d.%d\n",lib->Name, lib->Version,lib->major,lib->minor, lib->majorBuild, lib->build);


IppiRect roiRect={0,0, SRC_WIDTH,SRC_HEIGHT};
IppiSize srcSize={ SRC_WIDTH, SRC_HEIGHT};
IppiSize dstSize={ SRC_HEIGHT, SRC_WIDTH};
int dstwidthStep ;
int srcwidthStep;
Ipp8u* pSrcImg=ippiMalloc_8u_C3(SRC_WIDTH, SRC_HEIGHT, &srcwidthStep);
ippiImageJaehne_8u_C3R(pSrcImg,srcwidthStep, srcSize);
Ipp8u* pDstImgIPP = ippiMalloc_8u_C3(SRC_HEIGHT,SRC_WIDTH, &dstwidthStep);

double timeCalcIPP = (double)ippGetCpuClocks();
for (int my=0;myippiRemap_8u_C3R((Ipp8u*) pSrcImg, srcSize, srcwidthStep, roiRect,
pXTable, sizeof(float)*TARGET_WIDTH,
pYTable, sizeof(float)*TARGET_WIDTH,
(Ipp8u*) pDstImgIPP, dstwidthStep, dstSize,
IPPI_INTER_NN);

timeCalcIPP = (double)ippGetCpuClocks() - timeCalcIPP;
printf( " IPP calculating time = %gms\n", timeCalcIPP/(1.0*1000. * 100.0) );


return 0;
}

build with
g++ -m32 -o ImageTranspose ImageTranspose_ipp.cpp -I/opt/intel/ipp/include -L/opt/intel/ipp/lib/ia32 -lippi_l -lipps_l -lippcore_l -lm

Regards,
Ying

0 Kudos
moduspwnens
Beginner
478 Views
These are the parameters to the frei0r function:
instancethe effect instance
timethe application time in seconds but with subsecond resolution (e.g. milli-second resolution). The resolution should be at least the inter-frame period of the application.
inframe1the first incoming video frame (can be zero for sources)
inframe2the second incoming video frame (can be zero for sources and filters)
inframe3the third incoming video frame (can be zero for sources, filters and mixer2)
outframethe resulting video frame
inframe2 and inframe3 are not really meant to take xmap and ymap, but I think that I can still pass them in and use them that way.
Anyways, after I posted I realized that the x and ymapsteps should bew*h*sizeof(Ipp32f), however the problem is not with those parameters. The problem is with the srcStep parameter. It segfaults if I set it to anything other than 0, and I am wondering what might cause that.
EDIT: Actually, I don't understand why you are saying the x and ymapsteps should be w*h*sizeof(IpP32f). In your code you just do width*(sizeof(IPP32f)), so shouldn't I do the same?
0 Kudos
Ying_H_Intel
Employee
478 Views
Hello Moduspwnens,

It is not correct to set srcStep =0. If you add the Return Valuesst=ippiRemap , you actaully will get the error : ippStsStepErr. Indicates an error condition if one of the srcStep,dstStep, xMapStep, or yMapStep has a zero or negative value.
Yes,x/ymapsteps shouldbewidth*(sizeof(IPP32f)).

Anyway,it could behelpfultofinding the cause in quick wayif youcan provide usthe real input.
Would you pleasewrite( or print)the dataininframe1/inframe2/inframe3 to some files and attachedthem (by click Add Files)? (Ifthe inputframes are limited for public, you can sendby mark the post Private)

Regards,
Ying
0 Kudos
Reply