将cv2.resize源码写出来
时间: 2023-07-18 11:47:27 浏览: 120
cv2.resize的源码如下:
```python
def resize(src, dsize, fx=None, fy=None, interpolation=None):
"""
Resizes an image.
:param src: input image
:param dsize: output image size; if both fx and fy are set to None, it is interpreted as the output image
size and the aspect ratio is preserved.
:param fx: scale factor along the horizontal axis; if set to None, it is computed as (dsize[0] / src.shape[1])
:param fy: scale factor along the vertical axis; if set to None, it is computed as (dsize[1] / src.shape[0])
:param interpolation: interpolation method to use; defaults to INTER_LINEAR
:return: resized image
"""
if fx is None and fy is None:
fx = dsize[0] / src.shape[1]
fy = dsize[1] / src.shape[0]
elif fx is None:
fx = fy
elif fy is None:
fy = fx
if interpolation is None:
interpolation = cv2.INTER_LINEAR
return cv2.resize(src, dsize, fx=fx, fy=fy, interpolation=interpolation)
```
其中,cv2.resize是调用opencv库中的函数实现的,具体实现可以参考opencv官方文档。
阅读全文