#include"highgui.h"
using namespace cv;
int main(int argc, char** argv)
{
CvPoint2D32f srcTri[3],dstTri[3];
CvMat* rot_mat= cvCreateMat(2,3,CV_32FC1);
CvMat* warp_mat=cvCreateMat(2,3,CV_32FC1);
IplImage *src;
IplImage *warp_dst;
IplImage *warp_roate_dst;
if(argc==2 &&( src=cvLoadImage(argv[1],1))!=0)
{
warp_dst=cvCloneImage(src);
warp_dst->origin = src->origin;
cvZero(warp_dst);
srcTri[0]=Point2f(0,0);
srcTri[1]=Point2f(src->width-1,0);
srcTri[2]=Point2f(0,src->height-1);
dstTri[0]=Point2f(src->width*0.0, src->height*0.33);
dstTri[1]=Point2f(src->width*0.85,src->height*0.25);
dstTri[2]=Point2f(src->width*0.15,src->height*0.7);
cvGetAffineTransform(srcTri,dstTri,warp_mat);
cvWarpAffine(src,warp_dst,warp_mat);
cvCopy(warp_dst,src);
CvPoint2D32f center= cvPoint2D32f(src->width/2,src->height/2);
double angle=-50.0;
double scale=0.6;
cv2DRotationMatrix(center, angle,scale,rot_mat);
warp_roate_dst = cvCreateImage(cvGetSize(src),src->depth,3);
cvWarpAffine(src,warp_roate_dst,rot_mat);
// cvNamedWindow("src",1);
// cvShowImage("src",src);
cvNamedWindow("warp_dst",1);
cvShowImage("warp_dst",warp_dst);
cvNamedWindow("warp_roate_dst",1);
cvShowImage("warp_roate_dst",warp_roate_dst);
cvWaitKey(0);
}
cvReleaseImage(&warp_dst);
cvReleaseImage(&src);
cvReleaseImage(&warp_roate_dst);
cvReleaseMat(&warp_mat);
cvReleaseMat(&rot_mat);
return 0;
}
图片显示:
红色标记的那一行:提示自己不要忘记给变量开辟内存,我自己写的时候忘记了,导致一直编译不过~~~~~