双线性插值较为常用,原理参考http://www.cnblogs.com/linkr/p/3630902.html
下面给出代码:
void ImgResize_BiLinear()
{
cv::Mat imgSrc, imgDst1, imgDst2;
imgSrc = cv::imread("test.jpg");
imgDst1 = cv::Mat(cv::Size(imgSrc.cols*2, imgSrc.rows*2), imgSrc.type(), cv::Scalar::all(0));
imgDst2 = cv::Mat(imgDst1.size(), imgSrc.type(), cv::Scalar::all(0));
double scale_x = (double)imgSrc.cols / imgDst1.cols;
double scale_y = (double)imgSrc.rows / imgDst1.rows;
uchar* dataDst = imgDst1.data;
int stepDst = imgDst1.step;
uchar* dataSrc = imgSrc.data;
int stepSrc = imgSrc.step;
int iWidthSrc = imgSrc.cols;
int iHiehgtSrc = imgSrc.rows;
short cbufy[2];
float y_float, x_float;
int y_int, x_int;
short cbufx[2];
for (int j=0; j<imgDst1.rows; ++j)
{
y_float = (float)((j + 0.5) * scale_y - 0.5);
y