Ask Your Question

opencv transformation perspective

asked 2013-11-20 11:19:50 -0500

tymop gravatar image

updated 2013-11-20 11:56:56 -0500

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;



cvGetPerspectiveTransform(srcTri, dstTri, warp_mat);
cvWarpAffine( src, dst, warp_mat , CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS , cvScalarAll(0) );
edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted

answered 2013-11-20 13:59:43 -0500

I do not completely understand your situation, but use warpPerspective and not warpAffine. You want a perspective warp and an affine warp will not give you the desired results.

edit flag offensive delete link more


Thank you, that is good with this function.

tymop gravatar imagetymop ( 2013-11-20 15:13:28 -0500 )edit

If your question was answered, make sure to accept.

Der Luftmensch gravatar imageDer Luftmensch ( 2013-11-22 16:26:15 -0500 )edit

Question Tools

1 follower


Asked: 2013-11-20 11:19:50 -0500

Seen: 590 times

Last updated: Nov 20 '13