Download utils/tools.py from Bread-F/Intelligent-Medical-Guidance-Large-Model: direct link, hf CLI and curl.
- Browser
- Download file 611 Bytes
-
https://huggingface.co/spaces/Bread-F/Intelligent-Medical-Guidance-Large-Model/resolve/main/utils/tools.py
- Command line
-
hf download hf://spaces/Bread-F/Intelligent-Medical-Guidance-Large-Model/utils/tools.py
-
curl -L -o tools.py https://huggingface.co/spaces/Bread-F/Intelligent-Medical-Guidance-Large-Model/resolve/main/utils/tools.py
611 Bytes
| import cv2 | |
| def resize_image(image_path, max_height): | |
| """ | |
| 缩放图像,保持纵横比,将图像的高度调整为指定的最大高度。 | |
| 参数: | |
| - image_path: 图像文件的路径。 | |
| - max_height: 指定的最大高度值。 | |
| 返回: | |
| - resized_image: 缩放后的图像。 | |
| """ | |
| # 读取图片 | |
| image = cv2.imread(image_path) | |
| height, width = image.shape[:2] | |
| # 计算新的宽度,保持纵横比 | |
| new_width = int(width * max_height / height) | |
| # 缩放图片 | |
| resized_image = cv2.resize(image, (new_width, max_height)) | |
| return resized_image | |