当前位置: 首页 > news >正文

mirror_fold.py_utils_0207curso

import os

import random

import time

from typing import Dict, Optional, Tuple

import numpy as np

# 后视镜折叠场景配置(请按你的4种分辨率填写)

# key: (width, height) value: (x1, y1, x2, y2) 车辆黑色区域在原图上的像素坐标

MIRROR_FOLD_CAR_BOXES: Dict[Tuple[int, int], Tuple[int, int, int, int]] = {

# (960, 1088): (x1, y1, x2, y2),

# (1280, 720): (x1, y1, x2, y2),

# (1920, 1080): (x1, y1, x2, y2),

# (1440, 1080): (x1, y1, x2, y2),

}

# 若分辨率不在上表中,可用比例兜底(0-1),None 表示不启用兜底

MIRROR_FOLD_CAR_BOX_RATIOS: Optional[Tuple[float, float, float, float]] = None

# 是否启用后视镜折叠增强

MIRROR_FOLD_ENABLE = True

MIRROR_FOLD_PROB = 1.0 # 1.0=每次都做,0.5=50%概率

# 粉色色块颜色

MIRROR_FOLD_PINK_COLOR_BGR = (255, 0, 255) # OpenCV/BGR

MIRROR_FOLD_PINK_COLOR_RGB = (255, 0, 255) # PIL/RGB

# 语义分割标签填充值(按你的数据集语义修改)

FSD_PINK_VALUE = 1 # FSD中粉色区域视为可行驶

RM_PINK_VALUE = 0 # RM中粉色区域视为背景

# Debug保存(预处理后可视化)

MIRROR_FOLD_DEBUG_SAVE = False

MIRROR_FOLD_DEBUG_DIR = "runs/mirror_fold_debug"

MIRROR_FOLD_DEBUG_MAX = 200

MIRROR_FOLD_DEBUG_EVERY = 1

MIRROR_FOLD_DEBUG_ALPHA = 0.45

_debug_counts = {"det": 0, "fsd": 0, "rm": 0}


def _clamp_box(x1: int, y1: int, x2: int, y2: int, w: int, h: int) -> Optional[Tuple[int, int, int, int]]:

x1 = int(max(0, min(x1, w)))

x2 = int(max(0, min(x2, w)))

y1 = int(max(0, min(y1, h)))

y2 = int(max(0, min(y2, h)))

if x2 <= x1 or y2 <= y1:

return None

return x1, y1, x2, y2


def get_car_box_for_shape(width: int, height: int) -> Optional[Tuple[int, int, int, int]]:

car_box = MIRROR_FOLD_CAR_BOXES.get((width, height))

if car_box is None and MIRROR_FOLD_CAR_BOX_RATIOS is not None:

x1r, y1r, x2r, y2r = MIRROR_FOLD_CAR_BOX_RATIOS

car_box = (int(x1r * width), int(y1r * height), int(x2r * width), int(y2r * height))

if car_box is None:

return None

return _clamp_box(*car_box, w=width, h=height)


def build_pink_mask(width: int, height: int, car_box: Tuple[int, int, int, int]) -> Optional[np.ndarray]:

x1, y1, x2, y2 = _clamp_box(*car_box, w=width, h=height) or (None, None, None, None)

if x1 is None:

return None

mask = np.zeros((height, width), dtype=bool)

if x1 > 0:

mask[y1:y2, :x1] = True

if x2 < width:

mask[y1:y2, x2:] = True

return mask


def should_apply_mirror_fold() -> bool:

return MIRROR_FOLD_ENABLE and random.random() < MIRROR_FOLD_PROB


def get_debug_save_path(branch: str, img_path: str, suffix: str = "jpg") -> Optional[str]:

if not MIRROR_FOLD_DEBUG_SAVE:

return None

count = _debug_counts.get(branch, 0)

if count >= MIRROR_FOLD_DEBUG_MAX:

return None

if MIRROR_FOLD_DEBUG_EVERY > 1 and (count % MIRROR_FOLD_DEBUG_EVERY) != 0:

_debug_counts[branch] = count + 1

return None

_debug_counts[branch] = count + 1

base = os.path.splitext(os.path.basename(img_path))[0]

out_dir = os.path.join(MIRROR_FOLD_DEBUG_DIR, branch)

os.makedirs(out_dir, exist_ok=True)

ts = int(time.time() * 1000)

return os.path.join(out_dir, f"{base}_{count:06d}_{ts}.{suffix}")


http://www.jsqmd.com/news/355342/

相关文章:

  • 2026年知网AIGC检测又升级了?这样去痕迹才有效
  • 数字手势识别0-9检测数据集VOC+YOLO格式8738张10类别
  • 【数据结构-树与二叉树】4.3 二叉树的存储结构
  • 2026年术语保护好的去AIGC痕迹工具:专业词汇不乱改
  • 伦理委员会指南:高风险AI系统测试审批流程
  • 2026年文心一言写的内容怎么去AIGC痕迹?实测分享
  • pip 和 npm 区别
  • 2026年性价比最高的去AIGC痕迹工具:4.8元/千字
  • leetcode 916. Word Subsets 单词子集
  • 【无人机控制】基于LQR和PID控制器在风扰下对一维无人机高度稳定的控制效果附matlab代码
  • 2026年硕士论文去AIGC痕迹:15%以下怎么达标
  • 【控制】三自由度直升机的数据驱动模型预测控制附matlab代码
  • 2026最新MS胶品牌top5推荐!国内优质MS胶源头厂家权威榜单发布,资质服务双优助力高品质粘接 - 品牌推荐2026
  • malloc每秒百万次调用扛不住?看Nginx如何用500行代码打造零碎片内存池
  • Flutter 表单开发实战:表单验证、输入格式化与提交处理 - 指南
  • 深度剖析CVE-2025-40547:SolarWinds Serv-U关键漏洞技术解读
  • 04]delphi SynPDF 添加大纲(书签)
  • CANN ops-cv:AI 硬件端视觉算法推理训练的算子性能调优与实战应用详解
  • 【Agent】Toward Efficient Agents
  • 深圳软文发稿平台怎么选靠谱?媒介易助你抢占AI搜索时代流量红利 - 一搜百应
  • 2026年检测平台升级后去AIGC痕迹:最新应对方案
  • 【系统分析师】7.1 软件生命周期
  • CANN ops-transformer:大模型算子的硬件感知优化与异构计算架构协同设计
  • 告别“渣”男感!这些高性价比手动剃须刀 - 品牌测评鉴赏家
  • 【LLM】Clawbot的memory记忆机制
  • 2026年通义千问写的论文怎么去AIGC痕迹?降AI率攻略
  • 2026年有退款保障的去AIGC痕迹工具:不达标全额退
  • 真的太省时间!千笔AI,断层领先的AI论文软件
  • 2026NMN排名前十品牌推荐榜:第1名用户有效反馈与零差评 - 速递信息
  • 2026年Kimi写的内容怎么去AIGC痕迹?降AI率工具推荐