OpenCV图像的缩放

函数介绍:
    1.cvResize 改变图像大小

    void cvResize(const CvArr *src, CvArr *dst, int interpolation)
    函数说明:
    第一个参数表示输入图像。
    第二个参数表示输出图像。
    第三个参数表示插值方法,可以有以下四种:

    CV_INTER_NN - 最近邻插值,
    CV_INTER_LINEAR - 双线性插值 (缺省使用)
    CV_INTER_AREA - 使用象素关系重采样。当图像缩小时候,该方法可以避免波纹出现。当图像放大时,类似于     CV_INTER_NN 方法..
    CV_INTER_CUBIC - 立方插值.

    2.cvCreateImage(CvSize size, int depth, int channels)

    函数说明:
    第一个参数表示图像的大小。
    第二个参数表示图像的深度,可以为IPL_DEPTH_8U,IPL_DEPTH_16U等等。
    第三个参数表示图像的通道数。


#include "stdafx.h"
#include "iostream"
using namespace std;
#include "opencv2/opencv.hpp"

int main()
{
    const char *pImagePath = "E:/C_VC_code/Text_Photo/girl001.jpg";
    const char *pWindowsTitle = "MyFirst OpenCV";

    //load image from file
    IplImage *pImage = cvLoadImage(pImagePath,CV_LOAD_IMAGE_UNCHANGED);

    //create window
    cvNamedWindow(pWindowsTitle,CV_WINDOW_AUTOSIZE);

    //show image on window
    cvShowImage(pWindowsTitle,pImage);
    //------------------------以上创建显示原图--------------------------------

    const char *pDstImageTitle = "Auto Image";
    double fScale = 0.5; //the mul of 缩放
    CvSize cvSize;       //the size of changed image

    IplImage *pDstImage = NULL;

    //count the size of destination image
    cvSize.width = pImage->width*fScale;
    cvSize.height = pImage->height*fScale;

    //create image and auto
    pDstImage = cvCreateImage(cvSize, pImage->depth, pImage->nChannels);
    cvResize(pImage, pDstImage ,CV_INTER_AREA);

    //create window and show image
    cvNamedWindow(pDstImageTitle,CV_WINDOW_AUTOSIZE);
    cvShowImage(pDstImageTitle,pDstImage);

    //------------------------以上缩放并显示缩放图片--------------------------


    //wait key event
    cvWaitKey(0);

    //destroy window and release space
    cvDestroyWindow(pWindowsTitle);
    cvReleaseImage(&pImage);
    return 0;
}

结果展示:

原文地址:https://www.cnblogs.com/mypsq/p/4983295.html