接上一篇来说,将真实的样本过一遍baseline模型后得到最初版的boundingbox信息的txt文件,又将这些txt文件转成xml文件进行纠正,纠正后使用IphotoDraw导出的还是xml文件,因此还需要将这些xml文件再次转换成txt文件。(是不是很晕?哈哈,晕就对了,多想几遍就好了)

以下是以IphotoDraw为标注软件,将纠正好的xml文件转成txt文件的代码:

#coding:utf-8
#@Time:2017/6/16 19:37
#@author: xxx
import os
import re
import math
import string
from tqdm import tqdm# 提取xml文件中的矩形框四个角点跟标签def get_new_coord(center_coord,ori_coord,rotate_angle):x_new = (ori_coord[0]-center_coord[0])*math.cos((rotate_angle/180.)*math.pi)+(ori_coord[1]-center_coord[1])*math.sin((rotate_angle/180.)*math.pi)+center_coord[0]y_new = (ori_coord[1]-center_coord[1])*math.cos((rotate_angle/180.)*math.pi)-(ori_coord[0]-center_coord[0])*math.sin((rotate_angle/180.)*math.pi)+center_coord[1]return int(x_new),int(y_new)def get_coord_range(item):list_location = []for i in range(len(item)):if (item[i] == '"'):list_location.append(i + 1)X=item[list_location[0]:list_location[1]-1]Y=item[list_location[2]:list_location[3]-1]Width=item[list_location[4]:list_location[5]-1]Height=item[list_location[6]:list_location[7]-1]return X,Y,Width,Heightdef GetItemLocation(xml_file):fid=open(xml_file,"r",encoding="utf-8")list=[]for line in fid.readlines():line=line.replace("\n","")line=line.replace(" ","")list.append(line)str1 = "".join(list)label_list=re.findall("<Text>.*?</Text>",str1)position_list=re.findall("<Extent.*?/>",str1)angle_list=re.findall("<Data.*?>",str1)# 取出文本框标签label_list_new = []for label in label_list:result_label = label[6:-7]label_list_new.append(result_label)# 取出文本框旋转角度angle_list_new = []for angle in angle_list:result_angle = float(angle.split('"')[-2])angle_list_new.append(result_angle)#取出左上角点 w hposition_list_new = []for position in position_list:X, Y, Width, Height = get_coord_range(position)position_list_new.append([X, Y, Width, Height])# 得到标注框坐标point_list = []for i in range(len(position_list_new)):value = position_list_new[i]angle = angle_list_new[i]x1 = int(float(value[0]))  # 左上y1 = int(float(value[1]))x2 = int(float(value[0]) + float(value[2]))  # 右上y2 = int(float(value[1]))x3 = int(float(value[0]) + float(value[2]))  # 右下y3 = int(float(value[1]) + float(value[3]))x4 = int(float(value[0]))  # 左下y4 = int(float(value[1]) + float(value[3]))if not angle == 0:angle = -anglecenter_x = (x1 + x2 + x3 + x4) / 4center_y = (y1 + y2 + y3 + y4) / 4x1, y1 = get_new_coord([center_x, center_y], [x1, y1], angle)x2, y2 = get_new_coord([center_x, center_y], [x2, y2], angle)x3, y3 = get_new_coord([center_x, center_y], [x3, y3], angle)x4, y4 = get_new_coord([center_x, center_y], [x4, y4], angle)if int(x1) < 0:x1 = 0if (int(y1) < 0):y1 = 0if (int(y2) < 0):y2 = 0if (int(x4) < 0):x4 = 0point = [[x1,y1],[x2,y2],[x3,y3],[x4,y4]]point_list.append(point)return label_list_new,point_listif __name__=='__main__':path=r'xxxxxx'import globimport tracebackjpg_files=glob.glob(os.path.join(path,'*.jpg'))bar=tqdm(total=len(jpg_files))for file in jpg_files:bar.update(1)try:xml_file = file.replace('.jpg','_data.xml')label_list, position_list  = GetItemLocation(xml_file)# 左上 左下 右下 右上IMIMkey = file.split('\\')[-1].replace('.jpg', '')with open(os.path.join(path, IMIMkey + '.txt'), 'w+', encoding='utf-8') as fid:for i, label in enumerate(label_list):position = position_list[i]# flag = 0# if len(label) > 0:#     for dd in d:#         if dd in label:#             flag = 1#             breakflag = 1if flag == 1:fid.writelines(str(position[0][0]) + ',' + str(position[0][1]) + ',' +str(position[1][0]) + ',' + str(position[1][1]) + ',' +str(position[2][0]) + ',' + str(position[2][1]) + ',' +str(position[3][0]) + ',' + str(position[3][1]) +','+ label +'\n')except:print(file)traceback.print_exc()

将IphotoDraw标注好的xml文件转成txt文件(三)相关推荐

  1. 如何将xlsx表格文件转换成txt文件?

    #第二次写CSDN的文章,排版见谅. #主要的目的还是为了给自己留个纪念,十年二十年回过头来看,也是一件不错的事,能够看到自己的点滴成长,回首过往,如何从小菜鸟一步一步变成老菜鸟. #另一个目的就是现 ...

  2. windows 下如何将 二进制 bin 文件转换成 txt 文件,并对不同 txt 文件进行比对?

    1 所需要安装的软件: Git Bash 文件比对工具:Beyond Compare 4 2 bin 文件转换为 txt 文件的方法 运行 Git Bash , 执行如下命令即可: xxd mode1 ...

  3. python读取pdf文件并转换成txt文件

    将pdf文件转换成txt文件 官网 文档 中英文pdf都可以,而且处理速度很快,一秒可以处理10页左右 python2: pip install pdfminer python3: pip insta ...

  4. python批量实现labelImg标注的 xml格式数据转换成 txt格式保存

    labelImg标注的 xml格式数据如下: 单个xml文件数据打开如下: python实现labelImg标注的 xml格式数据转换成 txt格式数据的代码xml2txt.py如下: # -*- c ...

  5. Veri-776数据集处理 xml文件提取转换成txt文件

    Veri-776数据集处理 xml文件提取转换成txt文件 最近在做重识别工作,数据处理时需要进行文件格式转换,这里将代码记录下来 from os import getcwd import os fr ...

  6. C#.NET如何将cs文件编译成dll文件 exe文件 如何调用dll文件

    比如我要把TestDLL.cs文件编译成dll文件,则在命令提示符下,输入下面的命令,生成的文件为TestDLL.dll csc /target:library TestDLL.cs 注意前提是你安装 ...

  7. 将微信聊天记录转成txt文件的最实用方法

    将微信聊天记录转成txt文件的最实用方法 下载所需软件 获取微信聊天记录的数据库文件 获取打开数据库文件的密码 打开数据库文件 参考链接 下载所需软件 sqlcipher.exe,夜神模拟器,Hash ...

  8. json文件批量转为txt文件

    json文件批量转为txt文件 1 批量json标注文件: 2 json所对应的各个图片: 3 每个json文件内容: [{"type": 1,"x": 116 ...

  9. Java使用aspse实现Excel文件转换成PDF文件

    使用Java代码把Excel文件转换成PDF文件 需要引用aspose包,引入操作我写了一个博客,地址如下 https://blog.csdn.net/weixin_46713508/article/ ...

最新文章

  1. 链接详解--多目标文件的链接
  2. Android 核心分析 之六 -----IPC框架分析 Binder,Service,Se...
  3. EvenBus源码分析
  4. python整数类型提供了4种进制表示_关于整数类型的 4 种进制表示,哪个选项的描述是正确的?_学小易找答案...
  5. AngularJS 计时器
  6. .Net中json序列化与反序列化
  7. Android Gallery组件实现循环显示图像
  8. SpringBoot项目从Git拉取代码并完成编译打包启动的sh自动脚本
  9. 和显卡驱动要配套吗_显卡有必要更新驱动程序吗?老玩家的建议请收好
  10. Windows8 Metro应用开发之C#(3)- 数据控件ListView、GridView、FlipView
  11. (原创)无废话C#设计模式之二十:Mediator
  12. 多国电子书盈利模式分析
  13. 用条件断点寻找E盾的登录、合法、算法和取服务器数据CALL
  14. LinuxC学习日记
  15. win10无法连接到这个网络_win10以太网已连接无法上网怎么办?
  16. C语言:输出大写的三角形字母表(进阶)
  17. C++ 标准库的双向链表
  18. 商城模板_商城模板网站html5_微信小程序商城模板
  19. 磨金石教育摄影技能干货分享|近景拍摄技巧分析
  20. HBO Max for Mac(HBO Max客户端)

热门文章

  1. 游戏开发入门(七)特效系统
  2. Houdini图文笔记:常用函数及表达式(现学现卖更新中)
  3. 暑期项目实训7.19 论文复现+寻找并阅读新论文
  4. 护照阅读芯片读取技术SDK
  5. 盒子嵌套盒子行高问题
  6. 详解红黑树,图文并茂
  7. thinkphp 框架自动加载原理_thinkPHP5.0框架自动加载机制分析
  8. 2022年N2观光车和观光列车司机考试题及在线模拟考试
  9. 2021深圳500强企业榜单发布,法本信息榜上有名
  10. 创作了一幅春天的画作