#include <opencv2/opencv.hpp> using namespace std; int main() { double fScale = 0.2; //缩放倍数 CvSize czSize; //目标图像尺寸 //从文件中读取图像 IplImage *pSrcImage = cvLoadImage("F://19.jpg"); IplImage *pDstImage = NULL; //计算目标图像大小 czSize.width = pSrcImage->width * fScale; czSize.height = pSrcImage->height * fScale; //创建图像并缩放 pDstImage = cvCreateImage(czSize, pSrcImage->depth, pSrcImage->nChannels); cvResize(pSrcImage, pDstImage, CV_INTER_AREA); //创建窗口 cvNamedWindow("原图",0); cvNamedWindow("缩放图",0); //在指定窗口中显示图像 cvShowImage("原图", pSrcImage); cvShowImage("缩放图", pDstImage); //等待按键事件 cvWaitKey(); //保存图片 cvDestroyWindow("原图"); cvDestroyWindow("缩放图"); cvReleaseImage(&pSrcImage); cvReleaseImage(&pDstImage); return 0; }