Hi everyone,
I'm building a code where I have 4 corresponding 3d->2d points set manually, then I try to use fcvGeomHomographyFitf32 to get the homography which takes 3d points into those 2d points, and then use it to warp an image.
The problem is that I cannot get a correct homography, and my guess is that I'm filling fcvCorrespondences in a bad way, and of course, i cannot find any example. My result is always ---> matrix = {0,0,0,0,0,1,-0,-0,1} ¿?¿?¿ but it should be the identitymatrix (same points in to, and from)
Can someone help me with this problem?. I only need an example on how to fill correspondences struct and how to use homographies
Thank you all in advance.
PS: this is the code I'm using.
//FASTCV
float*__restrict matrix;
matrix = (float*) malloc(sizeof(float)*9);
fcvCorrespondences corrs;
const float32_t frompts[4*3] = {0.0f,0.0f,1.0f,marker.cols,0.0f,1.0f,marker.cols, marker.rows,1.0f,0.0f,marker.rows,1.0f};
corrs.from = (float32_t *)frompts;
corrs.fromStride=0;
uint16_t indicespts[4] = {0,1,2,3};
corrs.indices = (uint16_t*) indicespts;
corrs.numCorrespondences = 4;
corrs.numIndices = 4;
const float32_t topts[4*2] = {0.0f,0.0f,marker.cols,0.0f,marker.cols,marker.rows,0.0f,marker.rows};
corrs.to = (float32_t*)topts;
corrs.toStride=0;
fcvGeomHomographyFitf32 (&corrs, matrix);
Can you try the ' fcvGeomHomographyFitf32' function with the following setting for fromStride and toStride? I think the documentation is not correct where it says to set fromStride and toStride to 0.
corrs.fromStride = 3;
corrs.toStride = 2;
If the results you are getting is still incorrect, I will take a deeper look inside your code snippet.
Hi Prasun! Thank you, you were right, documentation is wrong, now I get a proper homography matrix with "corrs.fromStride = 3; corrs.toStride = 2". The homography I get is exactly the same I get with OpenCV findHomography function.
The problem is that, when I use that homography with the function fcvWarpPerspectiveu8, I always get a black image as a result.
My source image is 512*512 (multiple of 8), my destination image is 160*120 (both, multiple of 8), if I use the identity matrix, fcvWarpPerspectiveu8 works fine, but if I use the resultant homography of fcvGeomHomographyFitf32 it does not work properly. (I tested the homography with OpenCV function warpPerspective with good results)
I tried to normalize points between 0 and 1, I tried to change destination image size... but always black image as a result. Any idea about this?
Thank you :)
PS: my code again
//FASTCV
float*__restrict matrix;
matrix = (float* __restrict) malloc(sizeof(float)*9);
fcvCorrespondences corrs;
float width = marker.cols; //512
float height = marker.rows; //512
const float32_t frompts[4*3] = {0.0f,0.0f,0.0f,
width,0.0f,0.0f,
width,height,0.0f,
0.0f,height,0.0f};
corrs.from = (float32_t *)frompts;
corrs.fromStride=3;
uint16_t indicespts[4] = {0,1,2,3};
corrs.indices = (uint16_t*) indicespts;
corrs.numCorrespondences = 4;
corrs.numIndices = 4;
const float32_t topts[4*2] = {20.0f,20.0f,
100.0f,10.0f,
110.0f,60.0f,
10.0f,70.0f};
corrs.to = (float32_t*)topts;
corrs.toStride=2;
fcvGeomHomographyFitf32 (&corrs, matrix); //matrix OK -> same as OpenCV and tested with warpPerspective
Mat warpedFCV(Size(512,512), CV_8UC1);
fcvWarpPerspectiveu8(marker.data, marker.cols, marker.rows, warpedFCV.data, warpedFCV.cols, warpedFCV.rows, matrix);
Thank you for the quick response again, I already had a handmade bilinear warp perspective method, I just wanted to test fastcv's performance. I'll wait for the next release then... do you know about next release's timing plans?... ;-)
Thanks again!
Paula.
We expect to have it in the next couple of months; will update it in the Qualcomm's FastCV website as soon as it is available.