Ask Your Question
1

opencv transformation perspective

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

tymop gravatar image

updated 2013-11-20 11:56:56 -0600

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;

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

1 answer

Sort by » oldest newest most voted
2

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

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

Comments

Thank you, that is good with this function.

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

If your question was answered, make sure to accept.

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

Question Tools

1 follower

Stats

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

Seen: 639 times

Last updated: Nov 20 '13