<span style="font-family: Arial, Helvetica, sans-serif;">/* Warps image with perspective (projective) transform */</span>
CVAPI(void) cvWarpPerspective( const CvArr* src, CvArr* dst, const CvMat* map_matrix, int flags CV_DEFAULT(CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS), CvScalar fillval CV_DEFAULT(cvScalarAll(0)) );
参数与cvWarpAffine()相同,有一个小的但很重要的区别是所采用的映射矩阵必须是3x3的
CvMat* cvGetPerspectiveTransform( const CvPoint2D32f* pts_src, const CvPoint2D32f* pts_dst, CvMat* map_matrix );这里的pts_src和pts_dst是四个点的数组
void imageRotationP(void) { CvPoint2D32f srcQuad[4], dstQuad[4]; CvMat* warp_matrix = cvCreateMat(3, 3, CV_32FC1); IplImage *src, *dst; src=cvLoadImage("lena.jpg"); dst=cvCloneImage(src); dst->origin = src->origin; cvZero(dst); srcQuad[0].x=0;//src Top left srcQuad[0].y=0; srcQuad[1].x=src->width-1;//src Top right srcQuad[1].y=0; srcQuad[2].x=0;//src Bottom left srcQuad[2].y=src->height-1; srcQuad[3].x=src->width-1;//src Bottom right srcQuad[3].y=src->height-1; dstQuad[0].x=src->width*0.05;//dst Top left dstQuad[0].y=src->height*0.33; dstQuad[1].x=src->width*0.9;//dst Top right dstQuad[1].y=src->height*0.25; dstQuad[2].x=src->width*0.2;//dst Bottom left dstQuad[2].y=src->height*0.7; dstQuad[3].x=src->width*0.9;//dst Bottom right dstQuad[3].y=src->height*0.9; cvGetPerspectiveTransform( srcQuad, dstQuad, warp_matrix ); cvWarpPerspective(src, dst, warp_matrix); cvNamedWindow("Perspective_Warp", 1); cvShowImage("Perspective_Warp", dst); cvWaitKey(0); cvReleaseImage(&src); cvReleaseImage(&dst); cvReleaseMat(&warp_matrix); }
opencv 拉伸、扭曲、旋转图像-仿射变换
http://blog.csdn.net/u012005313/article/details/46714637