縮放灰階圖
cv::Mat bilinear(cv::Mat src, int row, int col){
int rows = src.rows, cols = src.cols;
cv::Mat dst(row, col, src.type());
for(int i = ; i < row; ++i) {
//以ptr的方式通路dst的資料
uchar *p = dst.ptr<uchar>(i);
//使兩個圖像的幾何中心重合,采樣更合理
float x = (i+)*rows/row-;
int fx = (int)x;
//x為坐标的小數部分
x -= fx;
//以整數計算速度更快
short x1 = (f-x)*;
short x2 = - x1;
for(int j = ; j < col; ++j) {
//trick
float y = (j+)*cols/col-;
int fy = (int)y;
y -= fy;
//trick
short y1 = (f-y)*;
short y2 = - y1;
//結果右移22位抵消2048的平方
p[j] = (src.at<uchar>(fx,fy)*x1*y1 + src.at<uchar>(fx+,fy)*x2*y1
+src.at<uchar>(fx,fy+)*x1*y2 + src.at<uchar>(fx+,fy+)*x2*y2) >> ;
}
}
return dst;
}