cv::resize用法
时间: 2023-10-08 08:12:28 浏览: 88
cv::resize函数是OpenCV中的一个图像处理函数,用于将一个图像缩放到指定的尺寸。它的用法如下:
```cpp
void resize(InputArray src, OutputArray dst, Size dsize, double fx = 0, double fy = 0, int interpolation = INTER_LINEAR );
```
其中:
- `src`:原始输入图像。支持CV_8U、CV_16U、CV_32F、CV_64F等多种数据类型。
- `dst`:输出缩放后的图像。与输入图像的数据类型一致。
- `dsize`:输出图像的尺寸。如果`fx`和`fy`都为0,则输出图像的尺寸由`dsize`指定;否则,输出图像的尺寸由原始图像的尺寸和缩放系数`fx`、`fy`共同决定。
- `fx`:水平方向的缩放系数,如果为0,则由`dsize`指定;否则,输出图像的宽度为`src.cols * fx`。
- `fy`:垂直方向的缩放系数,如果为0,则由`dsize`指定;否则,输出图像的高度为`src.rows * fy`。
- `interpolation`:插值方法,用于在缩放过程中计算新像素值。支持多种方法,包括最近邻插值、双线性插值、双三次插值等。
示例代码如下:
```cpp
cv::Mat src = cv::imread("lena.jpg");
cv::Mat dst1, dst2;
// 指定输出图像的尺寸
cv::resize(src, dst1, cv::Size(256, 256));
// 指定水平和垂直方向的缩放系数
cv::resize(src, dst2, cv::Size(), 0.5, 0.5);
cv::imshow("src", src);
cv::imshow("dst1", dst1);
cv::imshow("dst2", dst2);
cv::waitKey();
```
阅读全文
相关推荐

















