function Description:
1.cvResize changing image size
void cvresize (const Cvarr *SRC, Cvarr *dst, int interpolation)
function Description:
The first parameter represents an input image.
The second parameter represents an output image.
The third parameter represents an interpolation method, which can have the following four types:
Cv_inter_nn-Nearest neighbor interpolation,
Cv_inter_linear-bilinear interpolation (default use)
Cv_inter_area-resampling using pixel relationships. This method avoids ripples when the image shrinks. When the image is zoomed in, it resembles the Cv_inter_nn method :
cv_inter_cubic-cubic interpolation.
2.cvCreateImage (cvsize size, int depth, int channels)
function Description:
The first parameter represents the size of the image.
The second parameter represents the depth of the image, which can be ipl_depth_8u,ipl_depth_16u and so on.
The third parameter represents the number of channels for the image.
#include"stdafx.h"#include"iostream"using namespacestd; #include"opencv2/opencv.hpp"intMain () {Const Char*pimagepath ="e:/c_vc_code/text_photo/girl001.jpg"; Const Char*pwindowstitle ="Myfirst OpenCV"; //load image from FileIplimage *pimage =cvloadimage (pimagepath,cv_load_image_unchanged); //Create WindowCvnamedwindow (pwindowstitle,cv_window_autosize); //Show image on windowcvshowimage (pwindowstitle,pimage); //Create the original display------------------------above-------------------------------- Const Char*pdstimagetitle ="Auto Image"; DoubleFscale =0.5;//The mul of scaleCvsize cvsize;//The size of changed imageIplimage*pdstimage =NULL; //count the size of destination imageCvsize.width = pimage->width*Fscale; Cvsize.height= pimage->height*Fscale; //Create image and AutoPdstimage = Cvcreateimage (Cvsize, pimage->depth, pimage->nchannels); Cvresize (Pimage, Pdstimage, Cv_inter_area); //Create window and show ImageCvnamedwindow (pdstimagetitle,cv_window_autosize); Cvshowimage (Pdstimagetitle,pdstimage); //Zoom in------------------------above and display the zoom picture--------------------------//Wait key eventCvwaitkey (0); //Destroy window and release spaceCvdestroywindow (Pwindowstitle); Cvreleaseimage (&pimage); return 0;}
Results show:
OpenCV Scaling of images