// 哈哈镜制作
int main( int argc, char** argv )
{
IplImage* pImg; //声明IplImage指针
IplImage* pImg1; //声明IplImage指针
int i,j;
int method = 0;
CvSize size;
double tmp;
method = 8;
//method = HORAO;
//载入图像
pImg = cvLoadImage( "lena.jpg", 1);
cvNamedWindow( "Image", 1 );//创建窗口
cvShowImage( "Image", pImg );//显示图像
printf("imageSize: %d height: %d, width: %d, nChannels: %d\n", pImg->imageSize, pImg->height, pImg->width, pImg->nChannels);
//MaxFrame(pImg);
//MinFrame(pImg);
switch(method)
{
// 图像缩小
case DOWNRESIZE:
size = cvGetSize(pImg);
size.width = (size.width>>3)<<2; // 在OpenCV里边,widthStep必须是4的倍数,从而实现字节对齐,有利于提高运算速度。
size.height = size.height>>1;
pImg1 = cvCreateImage( size, IPL_DEPTH_8U, 1);
printf("imageSize: %d height: %d, width: %d, nChannels: %d\n", pImg1->imageSize, pImg1->height, pImg1->width, pImg1->nChannels);
for(i=0;i<pImg1->height;i++)
for(j=0;j<pImg1->width;j++)
{
pImg1->imageData[i*pImg1->width+j] = pImg->imageData[i*2*pImg->width+j*2];
}
break;
// 图像放大
case UPRESIZE:
/* 添加代码 */
break;
// 水平外凹
case HORAO:
pImg1 = cvCreateImage( cvGetSize(pImg), IPL_DEPTH_8U, 1);
printf("imageSize: %d height: %d, width: %d, nChannels: %d\n", pImg1->imageSize, pImg1->height, pImg1->width, pImg1->nChannels);
for(i=0;i<pImg1->height;i++)
{
tmp = RANGE*sin(i*PI/pImg1->height);
for(j=tmp;j<pImg1->width-tmp;j++)
{
pImg1->imageData[i*pImg1->width+j] = pImg->imageData[i*pImg->width+(int)((j-tmp)*(pImg->width)/(pImg->width-2*tmp))];
}
}
break;
// 水平外凸
case HORTU:
/* 添加代码 */
break;
// 梯形变形
case LADDER:
/* 添加代码 */
break;
// 三角形变形
case TRIANGLE:
/* 添加代码 */
break;
// S形变形
case SSHAPE:
/* 添加代码 */
break;
// 波浪形变形
case WAVESHAPE:
/* 添加代码 */
break;
case Concentrated:
MaxFrame(pImg);
break;
case Scattered:
MinFrame(pImg);
break;
default:
printf("no method support\n");
break;
}
// 显示结果
cvNamedWindow( "Image1", 1 );//创建窗口
cvShowImage( "Image1", pImg );//显示图像
cvWaitKey(0); //等待按键
//销毁窗口 释放内存
cvDestroyWindow( "Image" );//销毁窗口
cvReleaseImage( &pImg ); //释放图像
cvDestroyWindow( "Image1" );//销毁窗口
cvReleaseImage( &pImg1 ); //释放图像
return 0;
}
未完待续。。应该还有其他的算法,我再找找。
--------------------------------------分割线 --------------------------------------
Ubuntu Linux下安装OpenCV2.4.1所需包
CentOS下OpenCV无法读取视频文件
[翻译]Ubuntu 14.04, 13.10 下安装 OpenCV 2.4.9
--------------------------------------分割线 --------------------------------------