Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

opencv transformation perspective

Hello, I get a picture taken in perspective and wishes to restore its original form.

For this I use the code snippet below: My original image is in Dossard[j] . img

For the sake of simplicity, and because I did not understand why my resulting image corresponded to nothing , I put the same coordinate values ​​for the 2 images ( dstTri [0] = srcTri x [0] x . . ; ... ) . I thought in this case that the image given by cvWarpAffine would be exactly the original. But this is not the case , and this is just to ask me some help .

The original image is a rectangle 54 pixels wide by 56 pixels high) containing 4 figures photographed at a slight angle The resulting image is a cream white uniform image (note : I notice that the color corresponds to the first pixel of the original image Random . ? )

Is anyone know why I have this result and what am I doing wrong ?

Thank you in advance for your help. image descriptionimage description


    CvPoint2D32f srcTri[4], dstTri[4];
CvMat* warp_mat = cvCreateMat(2,3,CV_32FC1);
IplImage *src, *dst;

src = cvCloneImage( Dossard[j].img );
src->origin = Dossard[j].img->origin;
dst = cvCloneImage( src );
dst->origin = src->origin;

srcTri[0].x=0;srcTri[0].y=0;
srcTri[1].x=src->width;srcTri[1].y=0;
srcTri[2].x=src->width;srcTri[2].y=src->height;
srcTri[3].x=0;srcTri[3].y=src->height;

dstTri[0].x=srcTri[0].x;dstTri[0].y=srcTri[0].y;
dstTri[1].x=srcTri[1].x;dstTri[1].y=srcTri[1].y;
dstTri[2].x=srcTri[2].x;dstTri[2].y=srcTri[2].y;
dstTri[3].x=srcTri[3].x;dstTri[3].y=srcTri[3].y;

for (k=0;k<4;k++)
{
    printf("%f %f\n",srcTri[k].x,srcTri[k].y);
}

cvGetPerspectiveTransform(srcTri, dstTri, warp_mat);
cvWarpAffine( src, dst, warp_mat , CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS , cvScalarAll(0) );
cvSaveImage(buf2,dst,0);

opencv transformation perspective

Hello, I get a picture taken in perspective and wishes to restore its original form.

For this I use the code snippet below: My original image is in Dossard[j] . img

For the sake of simplicity, and because I did not understand why my resulting image corresponded to nothing , I put the same coordinate values ​​for the 2 images ( dstTri [0] = srcTri x [0] x . . ; ... ) . I thought in this case that the image given by cvWarpAffine would be exactly the original. But this is not the case , and this is just to ask me some help .

The original image is a rectangle 54 pixels wide by 56 pixels high) containing 4 figures photographed at a slight angle The resulting image is a cream white uniform image (note : I notice that the color corresponds to the first pixel of the original image Random . ? )

Is anyone know why I have this result and what am I doing wrong ?

Thank you in advance for your help. image descriptionimage description


 CvPoint2D32f srcTri[4], dstTri[4];
CvMat* warp_mat = cvCreateMat(2,3,CV_32FC1);
IplImage *src, *dst;

src = cvCloneImage( Dossard[j].img );
src->origin = Dossard[j].img->origin;
dst = cvCloneImage( src );
dst->origin = src->origin;

srcTri[0].x=0;srcTri[0].y=0;
srcTri[1].x=src->width;srcTri[1].y=0;
srcTri[2].x=src->width;srcTri[2].y=src->height;
srcTri[3].x=0;srcTri[3].y=src->height;

dstTri[0].x=srcTri[0].x;dstTri[0].y=srcTri[0].y;
dstTri[1].x=srcTri[1].x;dstTri[1].y=srcTri[1].y;
dstTri[2].x=srcTri[2].x;dstTri[2].y=srcTri[2].y;
dstTri[3].x=srcTri[3].x;dstTri[3].y=srcTri[3].y;

for (k=0;k<4;k++)
{
    printf("%f %f\n",srcTri[k].x,srcTri[k].y);
}

cvGetPerspectiveTransform(srcTri, dstTri, warp_mat);
cvWarpAffine( src, dst, warp_mat , CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS , cvScalarAll(0) );
cvSaveImage(buf2,dst,0);