vc++实现图像放大、缩小、平移、旋转、各种哈哈镜变形
// S形变形 case SSHAPE:
pImg1 = cvCreateImage(cvGetSize(pImg),pImg->depth,pImg->nChannels); for(i=0;i<pImg->height;i++) {
tmp = RANGE*sin(2*i*PI/pImg1->height+PI)+RANGE; for(j=tmp;j<pImg->width-(2*RANGE-tmp);j++) {
int s=(int)((j-tmp)*(pImg->width)/(pImg->width-RANGE*2)); for(int k=0;k<pImg->nChannels;k++) {
pImg1->imageData[i*pImg1->widthStep+j*pImg1->nChannels+k]=pImg->imageData[i*pImg->widthStep+s*pImg->nChannels+k];
} break;
}
}
//波浪形
case UNDAFORM:
pImg1 = cvCreateImage(cvGetSize(pImg),pImg->depth,pImg->nChannels); for(i=0;i<pImg->height;i++) {
for(j=0;j<pImg->width;j++) {
int s=(int)((4*i+pImg->height+pImg->height*sin(j*2*PI/pImg->width))/6); for(int k=0;k<pImg->nChannels;k++) {
pImg1->imageData[s*pImg1->widthStep+j*pImg1->nChannels+k]=pImg->imageData[i*pImg->widthStep+j*pImg->nChannels+k];
//图片旋转 case ROTATE:
width_rotate=int(pImg->height*fabs(sin (-angle * CV_PI / 180.))+pImg->width*fabs(cos height_rotate=int(pImg->width*fabs(sin (-angle * CV_PI / 180.))+pImg->height*fabs(cos pImg1 = cvCreateImage(cvSize(width_rotate,height_rotate),pImg->depth,pImg->nChannels);
} break;
}
}
(-angle * CV_PI / 180.))); (-angle * CV_PI / 180.)));