cvWarpAffine:仿射变换
2011-10-07 14:03
585 查看
右图中先通过创建点(平行四边形的顶点)的两个三元数组,然后利用cvGetAffineTransform()将其转换为具体的变换矩阵,从而得到cvWarpAffine()的矩阵参数。接下来,做一次仿射变换,紧接着将图像旋转。
#include "cv.h"
#include "highgui.h"
int _tmain(int argc, _TCHAR* argv[])
{
CvPoint2D32f srcTri[3],dstTri[3];
CvMat* rot_mat=cvCreateMat(2,3,CV_32FC1);
CvMat* warp_mat=cvCreateMat(2,3,CV_32FC1);
IplImage *src,*dst;
if(argc==2 && ((src=cvLoadImage(argv[1],1))!=0))
{
dst=cvCloneImage(src);
dst->origin =src->origin ;
cvZero(dst);
//compute warp matrix
srcTri[0].x =0; //src top left
srcTri[0].y=0;
srcTri[1].x =src->width -1; //src top right
srcTri[1].y=0;
srcTri[2].x=0; //src bottom left offset
srcTri[2].y=src->height -1;
dstTri[0].x=src->width *0.0; //dst top left
dstTri[0].y=src->height *0.33;
dstTri[1].x=src->width *0.85; //dst top right
dstTri[1].y=src->height *0.25;
dstTri[2].x=src->width *0.15; //dst bottom left offset
dstTri[2].y=src->height *0.7;
cvGetAffineTransform(srcTri,dstTri,warp_mat);
cvWarpAffine(src,dst,warp_mat);
cvCopy(dst,src);
//compute rotation matrix
CvPoint2D32f center=cvPoint2D32f(src->width /2,src->height /2);
double angle=-50.0;
double scale=0.6;
cv2DRotationMatrix(center,angle,scale,rot_mat);
//do the transformation
cvWarpAffine(src,dst,rot_mat);
cvNamedWindow("Affine_Transform",1);
cvShowImage("Affine_Transform",dst);
cvWaitKey();
}
cvReleaseImage(&dst);
cvReleaseMat(&rot_mat);
cvReleaseMat(&warp_mat);
return 0;
}
#include "cv.h"
#include "highgui.h"
int _tmain(int argc, _TCHAR* argv[])
{
CvPoint2D32f srcTri[3],dstTri[3];
CvMat* rot_mat=cvCreateMat(2,3,CV_32FC1);
CvMat* warp_mat=cvCreateMat(2,3,CV_32FC1);
IplImage *src,*dst;
if(argc==2 && ((src=cvLoadImage(argv[1],1))!=0))
{
dst=cvCloneImage(src);
dst->origin =src->origin ;
cvZero(dst);
//compute warp matrix
srcTri[0].x =0; //src top left
srcTri[0].y=0;
srcTri[1].x =src->width -1; //src top right
srcTri[1].y=0;
srcTri[2].x=0; //src bottom left offset
srcTri[2].y=src->height -1;
dstTri[0].x=src->width *0.0; //dst top left
dstTri[0].y=src->height *0.33;
dstTri[1].x=src->width *0.85; //dst top right
dstTri[1].y=src->height *0.25;
dstTri[2].x=src->width *0.15; //dst bottom left offset
dstTri[2].y=src->height *0.7;
cvGetAffineTransform(srcTri,dstTri,warp_mat);
cvWarpAffine(src,dst,warp_mat);
cvCopy(dst,src);
//compute rotation matrix
CvPoint2D32f center=cvPoint2D32f(src->width /2,src->height /2);
double angle=-50.0;
double scale=0.6;
cv2DRotationMatrix(center,angle,scale,rot_mat);
//do the transformation
cvWarpAffine(src,dst,rot_mat);
cvNamedWindow("Affine_Transform",1);
cvShowImage("Affine_Transform",dst);
cvWaitKey();
}
cvReleaseImage(&dst);
cvReleaseMat(&rot_mat);
cvReleaseMat(&warp_mat);
return 0;
}
相关文章推荐
- 稠密仿射变换 cvWarpAffine
- cvWarpAffine( src, dst, warp_mat ); //对图像做仿射变换
- 用opencv中的warpAffine获取仿射变换图片保存
- cvWarpPerspective:透视变换
- SimpleCV中shear()函数和warp()函数的区别
- SimpleCV中shear()函数和warp()函数的区别
- 图像变换-图像拉伸、收缩、扭曲、旋转[1] - 仿射变换(cvWarpAffine)
- 第六章 - 图像变换 - 图像拉伸、收缩、扭曲、旋转[1] - 仿射变换(cvWarpAffine)
- fitgeotrans,transformPointsForward,imwarp,非反射相似变换,相似变换,仿射变换
- 第六章 - 图像变换 - 图像拉伸、收缩、扭曲、旋转[1] - 仿射变换(cvWarpAffine)
- 第六章 - 图像变换 - 图像拉伸、收缩、扭曲、旋转[1] - 仿射变换(cvWarpAffine)
- 第六章 - 图像变换 - 图像拉伸、收缩、扭曲、旋转[1] - 仿射变换(cvWarpAffine)
- 图像变换 - 图像拉伸、收缩、扭曲、旋转 - 透视变换(cvWarpPerspective)
- opencv之透视变换cvWarpPerspective
- python opencv warpAffine
- OpenCV学习--仿射变换(affine)
- affine transformation matrix 仿射变换矩阵 与 OpenGL
- affine transformation matrix 仿射变换矩阵 与 OpenGL
- 图像变换 - 图像拉伸、收缩、扭曲、旋转[1] - 仿射变换(cvWarpAffine)
- 图像变换 - 图像拉伸、收缩、扭曲、旋转- 仿射变换(cvWarpAffine)