首页 / 操作系统 / Linux / OpenCV: 三对点计算仿射变换
OpenCV: 三对点计算仿射变换// 仿射变换.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <cv.h>
#include <highgui.h>
#include<windows.h>
#define affine
#ifdef affine
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, *dst;
if( argc == 1 && ((src=cvLoadImage("lenagray.jpg",1)) != 0 ))//原文中是argc == 2,错误
{
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
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
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);
cvWarpAffine(src,dst,rot_mat);
//DO THE TRANSFORM:
cvNamedWindow( "Affine_Transform", 1 );
cvShowImage( "Affine_Transform", dst );
cvWaitKey();
}
cvReleaseImage(&dst);
cvReleaseMat(&rot_mat);
cvReleaseMat(&warp_mat);
system("pause");
return 0;
}
#endif运行结果--------------------------------------分割线 --------------------------------------Ubuntu Linux下安装OpenCV2.4.1所需包 http://www.linuxidc.com/Linux/2012-08/68184.htmUbuntu 12.04 安装 OpenCV2.4.2 http://www.linuxidc.com/Linux/2012-09/70158.htmCentOS下OpenCV无法读取视频文件 http://www.linuxidc.com/Linux/2011-07/39295.htmUbuntu 12.04下安装OpenCV 2.4.5总结 http://www.linuxidc.com/Linux/2013-06/86704.htmUbuntu 10.04中安装OpenCv2.1九步曲 http://www.linuxidc.com/Linux/2010-09/28678.htm基于QT和OpenCV的人脸识别系统 http://www.linuxidc.com/Linux/2011-11/47806.htm--------------------------------------分割线 --------------------------------------OpenCV的详细介绍:请点这里
OpenCV的下载地址:请点这里本文永久更新链接地址:http://www.linuxidc.com/Linux/2014-10/108689.htm