ReportGeneration/utils/cv_tools.py

18 lines
577 B
Python
Raw Normal View History

2024-07-26 16:42:17 +08:00
import cv2
def resize_image(input_path, output_path, new_width=200):
# 读取原始图片
img = cv2.imread(input_path, cv2.IMREAD_UNCHANGED)
# 计算新的高度,保持纵横比
height, width = img.shape[:2]
width_percent = (new_width / float(width))
new_height = int((float(height) * width_percent))
# 调整图片大小
resized_img = cv2.resize(img, (new_width, new_height), interpolation=cv2.INTER_LANCZOS4)
# 保存调整后的图片
cv2.imwrite(output_path, resized_img)
print(f"图片已保存为 {output_path}")