vc++实现图像放大、缩小、平移、旋转、各种哈哈镜变形
#define PI 3.1415926
// 哈哈镜制作
int main( int argc, char** argv ) {
IplImage* pImg; //声明IplImage指针 IplImage* pImg1; //声明IplImage指针 int i,j;
int x,y; int method; CvSize size; double tmp;
int angle = 45; double factor;
float m[6]; int width_rotate; int height_rotate;
CvMat M = cvMat (2, 3, CV_32F, m);
printf("0: 缩小\n1: 放大\n2: 水平外凹\n3: 水平外凸\n4: 梯形变形\n5: 三角形变形\n6: S形变形printf("请输入数字0—7,选择你需要的变换:\n"); scanf("%d",&method);
\n7: 图片旋转\n8: 图片平移\n");
//载入图像
pImg = cvLoadImage( "gg.bmp", 1); cvNamedWindow( "Image", 1 );//创建窗口 cvShowImage( "Image", pImg );//显示图像
printf("%d,%d",pImg->width,pImg->height); switch(method) {
// 最邻近插值图像缩小 case DOWNRESIZE:
size = cvSize(q*pImg->width,q*pImg->height); for(i=0;i<pImg1->height;i++)
for(j=0;j<pImg1->width;j++) {
float srcX=(float)(j*((float)pImg->width/(float)pImg1->width)); float srcY=(float)(i*((float)pImg->height/(float)pImg1->height)); int int_srcX=(int)srcX; int int_srcY=(int)srcY;
for(int k=0;k<pImg1->nChannels;k++)
pImg1 = cvCreateImage(size,pImg->depth,pImg->nChannels);