//透视变换
int WarpPerspective(IplImage *grey)
{
IplImage* Img_old = cvCloneImage( grey );
float fix = 4;
float w = (float)Img_old->width + fix;
float h = (float)Img_old->height + fix;
CvPoint2D32f src_point[4];
CvPoint2D32f dst_point[4];
//设定源观察面,即指定四边形的四个顶点
src_point[0].x=4;
src_point[0].y=105;
src_point[1].x=285;
src_point[1].y=139;
src_point[2].x=8;
src_point[2].y=8;
src_point[3].x=289;
src_point[3].y=33;
//设定目标观察面,即指定四边形的四个顶点
dst_point[0].x=-fix;
dst_point[0].y=h;
dst_point[1].x=w;
dst_point[1].y=h;
dst_point[2].x=-fix;
dst_point[2].y=-fix;
dst_point[3].x=w;
dst_point[3].y=-fix;
float newm[9];
CvMat newM = cvMat( 3, 3, CV_32F, newm );
//获得透视转换矩阵
cvWarpPerspectiveQMatrix(src_point,dst_point,&newM);
//透视转换
cvWarpPerspective(Img_old,grey,&newM,CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS, cvScalarAll(0) );
cvNamedWindow("ImgWarp",1);
cvShowImage("ImgWarp",grey);
cvWaitKey(0);
cvReleaseImage(&Img_old);
return 0;
}
//测试投射变换
int Quadrangle(IplImage *grey)
{
IplImage* src = cvCloneImage( grey );
float m[6];
int angle = -15;
CvMat M = cvMat( 2, 3, CV_32F, m );
int w = src->width;
int h = src->height;
m[0] = (float)(cos(angle*CV_PI/180.));
m[1] = (float)(sin(angle*CV_PI/180.));
m[2] = w*0.5f;
m[3] = -m[1];
m[4] = m[0];
m[5] = h*0.5f;
cvGetQuadrangleSubPix( src, grey, &M);
return 0;
}