OpenCV Scaling of images

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.