cvResize
函数功能:图像大小变换
函数原型:
voidcvResize(
const CvArr*src,
CvArr* dst,
intinterpolation=CV_INTER_LINEAR
);
函数说明:
第一个参数表示输入图像。
第二个参数表示输出图像。
第三个参数表示插值方法,可以有以下四种:
CV_INTER_NN -最近邻插值,
CV_INTER_LINEAR -双线性插值 (缺省使用)
CV_INTER_AREA -使用象素关系重采样。当图像缩小时候,该方法可以避免波纹出现。当图像放大时,类似于 CV_INTER_NN方法..
CV_INTER_CUBIC -立方插值.
这个函数在功能上与Win32 API中的StretchBlt()函数类似。
应用:
#include "stdafx.h"
#include <opencv.hpp>
#include <cxcore.h>
#include <highgui.h>
#include <stdio.h>
int main()
{
IplImage *ImageInfo = cvLoadImage("1.jpg");//读取图像
unsigned short mWide = ImageInfo->width;
unsigned short mHeight = ImageInfo->height;
unsigned char *ImageData = (unsigned char*)ImageInfo->imageData;
unsigned char nChannel = ImageInfo->nChannels;
double fscale=0.314;//缩放系数
int SmallWide =mWide*fscale;//缩放后的宽度
int SmallHeight=mHeight*fscale;//缩放后的高度
IplImage *GrayImage = cvCreateImage(cvSize(mWide,mHeight),8,1);//新建图像函数
IplImage *SmallImage = cvCreateImage(cvSize(SmallWide,SmallHeight),8,3);//新建缩放图像函数
cvCvtColor(ImageInfo,GrayImage,CV_RGB2GRAY);//将彩色图像改为灰度图像
cvResize(ImageInfo,SmallImage,CV_INTER_AREA);//将图像缩放
printf("mWide = %d\r\n mHeight = %d\r\n nChannel = %d\r\n SmallWide=%d\r\n SmallHeight=%d\r\n",mWide,mHeight,nChannel,SmallWide,SmallHeight);
cvNamedWindow("the Image of show:");//创建窗口函数
cvShowImage("the Image of show:",ImageInfo);//显示函数
cvNamedWindow("the GrayImage of show:");//创建窗口函数
cvShowImage("the GrayImage of show:",GrayImage);//显示函数
cvNamedWindow("缩放图:");//创建窗口函数
cvShowImage("缩放图:",SmallImage);//显示函数
cvWaitKey(-2);//等待按键事件
return 0;
}