OpenCV using the Cvresize function or the resize function for image scaling

Source: Internet
Author: User

Cvresize function prototypes
voidconstint interpolation=cv_inter_linear);

SRC: Enter an image. (iplimage)

DST: Output image. (iplimage)

Interpolation: Difference Method:

Cv_inter_nn-Nearest Neighbor Difference value

Cv_inter_linear-bilinear difference value (default use)

Cv_inter_area-resampling using pixel relationships. This method avoids ripples when the image shrinks. Similar to the Cv_inter_nn method when the image is enlarged

Cv_inter_cubic-Cubic difference

The function cvresize changes the image src size to get the same sizes as DST. If you set ROI, the function will support the ROI as usual.

Image scaling using the Resize function when programming with C + +

Resize-Letter Prototype
void Resize (inputarray src, outputarray DST, double fx=0double fy=0 , int interpolation=inter_linear);

Note: Dsize and (fx,fy) cannot be 0 simultaneously

Sample program:

Using UBUNTU14.04+OPENCV 3.1.0

/**------------------------------------------------------------------**//** Description: Contains the header file that the program depends on **//**------------------------------------------------------------------**/#include<opencv2/opencv.hpp>#include<opencv2/highgui/highgui.hpp>#include<opencv2/imgproc/imgproc.hpp>#include<string>/**------------------------------------------------------------------**//** Description: Namespace used by the program **//**------------------------------------------------------------------**/using namespaceCV;using namespacestd;/**------------------------------------------------------------------**//** Description: System Global Constants **//**------------------------------------------------------------------**///The file name of the target image that needs to be placed in the project directoryConst stringTagrimg ="Angelababy.jpeg";//Defining window TitlesConst CharSrcwinna[] ="Srcwindow";Const CharGrywinna[] ="Grywindow";Const CharReswinna[] ="Reswindow";/**------------------------------------------------------------------**//** Description: System global Variables **//**------------------------------------------------------------------**///Zoom in and outDoublescale=0.4;intMainintargcChar**argv) {    /** Read and display the original image-----------------------------------------------**/    //Reading PicturesMat srcimg =Imread (TAGRIMG); //Check if Read succeeded    if(!srcimg.data) {cout<<"read failed, program aborted"<<Endl; cout<<"Please check the project directory for presence"<<TagrImg<<Endl; return-1; }    //Create window to display the original imageCvnamedwindow (Srcwinna, cv_window_autosize);        Imshow (Srcwinna, srcimg); /** Image Zoom and display--------------------------------------------------**/    //set the size of a scaled pictureSize Resimgsiz = Size (Srcimg.cols*scale, srcimg.rows*Scale ); Mat resimg=Mat (Resimgsiz, Srcimg.type ());    Resize (srcimg, resimg, Resimgsiz, cv_inter_cubic); //Create a window to display scaled imagesCvnamedwindow (Reswinna, cv_window_autosize);    Imshow (Reswinna, resimg); Cvwaitkey (0); return 1;}

Reduce the picture to 0.5 times times:

OpenCV using the Cvresize function or the resize function for image scaling

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.