缩放图像

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; 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值