OpenCV中提供了图像尺寸调整的函数resize(),函数介绍如下:
void resize(
InputArray src,
OutputArray dst,
Size dsize,
Double fx=0,
Double fy=0,
int interpolation=INTER_LINEAR
)
第一个参数:InputArray src输入图像
第二个参数:OutputArray dst输出图像
第三个参数: 输出图像的尺寸,如果是0,则有
dsize=Size(round(fx*src.cols),round(fy*src,rows))计算得出
第四个参数:x轴的缩放系数,默认为0
第五个参数:y轴的缩放系数,默认为0
第六个参数:插值方式,默认为INTER_LINEAR线性插值
下面是代码:
#include <opencv2/opencv.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
int main()
{
Mat srcImage = imread("1.jpg");
Mat temImage, dstImage1, dstImage2;
temImage = srcImage;
imshow("原图", srcImage);
//尺寸调整
resize(temImage, dstImage1, Size(temImage.cols / 2, temImage.rows / 2), 0, 0, INTER_LINEAR);
resize(temImage, dstImage2, Size(temImage.cols * 2, temImage.rows * 2), 0, 0, INTER_LINEAR);
imshow("缩小", dstImage1);
imshow("放大", dstImage2);
waitKey();
return 0;
}
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/nonfree/features2d.hpp> //
#include <opencv2/imgproc/imgproc.hpp> // resize()
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, const char *argv[]){
Mat big = imread("imgs/linux.jpg",-1);//CV_LOAD_IMAGE_ANYDEPTH);// the big pic
Mat dst = imread("imgs/200X200.jpg", -1);
cout << "Mat info:" << endl;
cout << "Original pic," << big.rows << " : "<< big.cols << endl;
cout << "dst pic, " << dst.rows << " : "<< dst.cols << endl;
Size s = big.size();
cout << "Pic Size info:" << endl;
cout << "Original pic," << s.width << " : "<< s.height << endl;
s = dst.size();
cout << "dst pic," << s.width << " : "<< s.height << endl;
// resize big to dst
cv::resize(big, dst, dst.size());
// show it on an image
imshow("big", big);
imshow("test", dst);
waitKey(0);
return 0;
}
---------------------
原文:https://blog.csdn.net/qq78442761/article/details/54312597