xml的检测框剪裁后分割,还原到原图的分割坐标保存json

import os
import json
import xml.etree.ElementTree as ET
import cv2
import numpy as np

# 假设你的分割模型和配置
from paddleseg import PaddleSeg

# 分割模型初始化
model = PaddleSeg(config='path_to_config', model_path='path_to_model')

def seg_img(img):
    # 运行分割模型
    pred = model(img)  # 根据你的模型进行适当调整
    
    # 假设 pred 是分割后的结果,且pred是一个与输入图像同大小的数组,其中0, 1, 2分别表示背景,帽子,手套
    # 我们只提取标签为1(帽子)的分割轮廓
    pred = (pred == 1).astype(np.uint8)
    
    # 找到分割轮廓
    contours, _ = cv2.findContours(pred, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
    
    if not contours:
        return []
    
    # 找到面积最大的轮廓
    max_contour = max(contours, key=cv2.contourArea)
    
    return max_contour

def expand_box(box, img_width, img_height, expansion_factor=0.15):
    # 扩展检测框
    xmin, ymin, xmax, ymax = box
    width = xmax - xmin
    height 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值