#include <cv.h>
#include <highgui.h>
// 可以用来旋转图像
int main()
{
CvMat *rot_mat = cvCreateMat(2,3,CV_64FC1);
CvMat *warp_mat = cvCreateMat(2,3,CV_64FC1);
CvPoint2D32f srcTri[3],dstTri[3];
IplImage *src,*dst;
src=cvLoadImage("D:/a_project/save/12.jpg",1);
dst=cvCreateImage(cvGetSize(src),src->depth,src->nChannels);
cvNamedWindow("原图",1);
cvShowImage("原图",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;
dstTri[0].x=src->width*0.1;
dstTri[0].y=src->height*0.1;
dstTri[1].x=src->width*0.6;
dstTri[1].y=src->height*0.6;
dstTri[2].x=src->width*0.3;
dstTri[2].y=src->height*0.8;
cvGetAffineTransform(srcTri,dstTri,warp_mat); //由不共线的三点计算仿射变换 ,变换矩形 warp_mat,实际应用中,要自己求
cvWarpAffine(src,dst,warp_mat);
cvCopy(dst,src);
// cvNamedWindow("仿射",1);
//cvShowImage("仿射",dst);
CvPoint2D32f center = cvPoint2D32f(src->width/2,src->height/2);
double angle = -30.0;
double scale = 1;
cv2DRotationMatrix( center, angle, scale, rot_mat );
cvWarpAffine(src,dst, rot_mat );
cvNamedWindow("仿射2",1);
cvShowImage("仿射2",dst);
cvWaitKey();
return 0;
}
图像仿射变换
最新推荐文章于 2023-08-31 10:39:04 发布