These two functions are the image scaling
function described
void CV :: a resize (InputArray the src,
outputArray DST,
Size. Dsize,
Double FX = 0,
Double FY = 0,
int interpolation = INTER_LINEAR
)
in front of three variables need not be described,
FX scale factor along the horizontal axis; when it is 0, as no wake up, the function will be according to reshape the width and height dsize, fy similar
Use
rc is reduced to 0.2 times the original in two ways;
a first
cv::resize(img,ResImg,Size(),0.2,0.2);
And relatively little trouble in the second
Size ResImgSize=Size(img.cols*scale,img.rows*scale);
cv::resize(img,ResImg,ResImgSize,0,0);
Note that when the third variable is not empty when dsize, fx, fy not be ignored
Routine
#include<iostream>
//opencv基础
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
//for reSize()
#include<opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
//缩放倍数为0.5
double scale = 0.5;
int main()
{
cv::Mat img=cv::imread("/data/girl.jpg");
if(!img.data)
{
cout<<"文件读取失败,请确认文件路径及文件名"<<endl;
return -1;
}
cvNamedWindow("原始图像",CV_WINDOW_AUTOSIZE);
imshow("原始图像",img);
cout<<"原始图像的行为: "<<img.rows<<"\t原始图像的列为: "<<img.cols<<endl;
Size ResImgSize=Size(img.cols*scale,img.rows*scale);
cv::Mat ResImg(ResImgSize,img.type());
cv::resize(img,ResImg,ResImgSize,0.2,0.2);
cvNamedWindow("重塑图像",CV_WINDOW_AUTOSIZE);
imshow("重塑图像",ResImg);
cout<<"重塑图像的行为: "<<ResImg.rows<<"\t重塑图像的列为: "<<ResImg.cols<<endl;
cv::waitKey();
}
The main reference https://docs.opencv.org/3.4/da/d54/group__imgproc__transform.html#ga47a974309e9102f5f08231edc7e7529d