需求：仔细审核和分析【】内提供的目标检测的源代码，目前图片的格式仅仅支持('.jpg', '.jpeg', '.png', '.bmp'),帮我修改一下代码，让整个程序也支持.webp格式的图片的读写和算法分析。怎么修改？请最后请给出修改后的完整代码。
【
import argparse
from ultralytics import YOLO
import cv2
import os
from pathlib import Path
import re


def transform_string(input_str):
    """
    将类似 "['Fire', ['Fire', 'fire']] 0.83" 的字符串转换为 "Fire 0.83"

    参数:
        input_str (str): 输入的字符串

    返回:
        str: 转换后的字符串
    """
    # 定义正则表达式模式
    pattern = r"\['(\w+)',\s*\[.*\]\]\s*([\d.]+)"

    # 使用 re.match 尝试匹配整个字符串
    match = re.match(pattern, input_str)

    if match:
        word = match.group(1)
        number = match.group(2)
        return f"{word} {number}"
    else:
        # 如果格式不匹配，可以选择返回原字符串或处理为其他方式
        return input_str

def parse_args():
    parser = argparse.ArgumentParser(description='YOLOv8 Object Detection')
    parser.add_argument('--modelname', type=str, required=True, help='Path to YOLOv8 model')
    parser.add_argument('--image_path', type=str, required=True, help='Path to image folder')
    return parser.parse_args()


def detect_objects(model_path, image_folder):
    model_path = model_path.replace(" ", "")
    image_folder = image_folder.replace(" ", "")
    # （1）删除以 "_result.jpg" 结尾的图片
    result_extensions = ['.jpg', '.jpeg', '.png', '.bmp']
    for ext in result_extensions:
        result_images = list(Path(image_folder).glob(f'*_result{ext}'))
        result_images.extend(Path(image_folder).glob(f'*_result{ext.upper()}'))
        for img_path in result_images:
            try:
                os.remove(img_path)
                print(f"已删除旧的结果图片: {img_path}")
            except Exception as e:
                print(f"无法删除文件 {img_path}: {e}")

    # 加载 YOLOv8 模型
    model = YOLO(model_path)

    # 获取文件夹中的所有图片文件
    image_extensions = ['.jpg', '.jpeg', '.png', '.bmp']
    image_files = []
    for ext in image_extensions:
        image_files.extend(Path(image_folder).glob(f'*{ext}'))
        image_files.extend(Path(image_folder).glob(f'*{ext.upper()}'))

    # 处理每张图片
    for img_path in image_files:
        # 跳过已处理的结果图片（已删除，但以防万一）
        if '_result' in img_path.stem:
            continue
        # 读取图片
        img = cv2.imread(str(img_path))
        if img is None:
            print(f"无法读取图片: {img_path}")
            continue

        # 进行目标检测
        results = model(img)

        # 吸烟单独处理
        if "吸烟" in str(img_path):
            if results[0].boxes.shape[0] < 1:
                results = model.predict(img, save=True, classes=0, conf=0.02, iou=0.2)
            else:
                results = model.predict(img, save=True, classes=0, conf=0.28, iou=0.5)
        # 打电话单独处理
        if "打电话" in str(img_path):
            if results[0].boxes.shape[0] < 1:
                results = model.predict(img, conf=0.03, save=True, classes=0, iou=0.1)
            else:
                results = model.predict(img, conf=0.47, save=True, classes=0, iou=0.7)

        # 获取第一个结果
        result = results[0]

        # 绘制边界框和标签
        for box in result.boxes:
            # 获取边界框坐标
            x1, y1, x2, y2 = box.xyxy[0]
            x1, y1, x2, y2 = int(x1), int(y1), int(x2), int(y2)

            # 获取置信度和类别
            conf = float(box.conf)
            cls = int(box.cls)
            # （2）修改这里，确保类别名称格式正确
            class_name = result.names[cls]
            if isinstance(class_name, list):
                class_name = class_name[0]
            elif not isinstance(class_name, str):
                class_name = str(class_name)
            label = f"{class_name} {conf:.2f}"
            label = transform_string(label)

            # 绘制边界框
            cv2.rectangle(img, (x1, y1), (x2, y2), (0, 255, 0), 2)

            # 绘制标签
            cv2.putText(img, label, (x1, max(y1 - 10, 0)), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)

        # 生成输出路径
        output_path = img_path.parent / f"{img_path.stem}_result{img_path.suffix}"

        # 保存结果
        cv2.imwrite(str(output_path), img)
        print(f"处理完成: {img_path} -> {output_path}")


def main():
    args = parse_args()
    detect_objects(args.modelname, args.image_path)


if __name__ == "__main__":
    main()
】