Hi everyone, I'm trying to use fcvTransformAffine8x8u8 function, but I cannot set the parameters corretly. I'm having issues with this two parameters:
nPos[2 ] Position in the image in 32 bit fixed pointWARNING: must be 64-bit aligned.nAffine[2 ][ 2 ] Transformation matrix in 32 bit fixed point
WARNING: must be 128-bit aligned.
I cannot make it work, not even with hardcoded values.
Have someone tested that functions?
Thank in advance,
Paula.
Hi Paula,
The function transforms a canonical 8x8 rectanlge centered at 0,0 to a region in the image and samples in that small region.
nPos[2] is the translation component of the affine transform in 32 bit fixed point
affine[2][2] is the rotation and scaling component also in 32 bit fixed point.
Below is a code snipet that shows how the function can be used.
static inline int float2Fx32( float nFloat )
{
int fixed = ( int )( nFloat*( 1<<16 ) );
return fixed;
}
static void float2Fx32( float * nFloat, int* fixed,int size )
{
for ( int k = 0; k < size; k++ )
{
fixed[ k ] = float2Fx32( nFloat[ k ] );
}
}
float posf[2], matf[4];
posf[ 0 ] = 12.25f; posf[ 1 ] = 52.0f;
matf[0] = 0.013717344f;
matf[1] = 0.69070274f;
matf[2] = -0.67423344f;
matf[3] = 0.024732463f;
//Make sure arrays are 128 bits aligned
int FASTCV_ALIGN128(posi32[2]), FASTCV_ALIGN(mati32[4]);
float2Fx32( posf,posi32,2 );
float2Fx32( matf,mati32,4 );
unsigned char FASTCV_ALIGN128(img[480*320]);
unsigned char FASTCV_ALIGN128(patch[8*8]);
int res = fcvTransformAffine8x8u8( img,480,320, posi32, mati32, patch);
Cheers,
Guy
The above code provides a very good description of using the TransformAffine8x8 function and should work as expected. In general, whenver there is a byte mis-alignment (of size 4, 8, 16), one can use the following FastCV macro functions to align the data properly:
FASTCV_ALIGN32 // macro to align memory at 4 bytes (32 bits)
FASTCV_ALIGN64 // macro to align memory at 8 bytes (64 bits)
FASTCV_ALIGN128 // macro to align memory at 16 bytes (128 bits)
Thanks!
Hi Guy, I'm still struggling to get good results, about your comments.
1. Result:
Reading Qualcomm's FastCV documentation it says:
FASTCV_API int fcvTransformAffine8x8u8 [...] Returns: true if the transformation is valid
FASTCV_API int fcvTransformAffineu8 [...] Returns: true if the transformation is valid
So my guess was: result == 0 --> false, hence error; resulta == 1 --> true , hence OK
(y always get 0, yep)
2. Typo
It isn't a typo, OpenCV stores width and height that way:
width = number of columns of an image
height = number of rows of an image
(anyway I tried inverting those numbers, but same behavior ocurred)
Next, I followed your advice and tested int fcvTransformAffineu8:
Sadly on the documentation they don't specify source and destination alignments, and the parameters "position" and "affine" are different types comparing with fcvTransformAffine8x8u8 (the are not 32bit fixed point anymore)
I tried everything possible, I'm starting to feel desperate, it's been a whole week for just warping an image. It should't be that difficult...
Just a final question. Has someone tested any of these functions sucessfully?
Thank you for your help, sincerilly.
Paula.