接上一篇来说,将真实的样本过一遍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. 清华大学大数据研究中心“RONG”奖学金申请通知
  2. linux内核中的 哈希表_Linux内核中的设备模型及SCSI示例解析
  3. adas技术实现途径_未来实现100%清洁电力的途径,带来巨大的健康和工作
  4. shell脚本获取系统的前一天日期,格式为yyyymmdd
  5. php无get报错,php $_get报错怎么办
  6. android 动态设置View的高度和宽度,ViewTreeObserver使用
  7. Matplotlib - plot用例
  8. 剑指offer.从未到头打印链表
  9. MSDN 离线帮助文档 官网极速下载直达
  10. 数据挖掘概念与技术学习笔记(1)
  11. 三星c9000刷android7.0,三星C9 Pro C9000官方原厂rom线刷包刷机包C9000ZCU1CRI1
  12. zhaow游戏知识问答
  13. 微信聊天防封 亲测 百分之95有效 【附源码】
  14. 孙子兵法——三十六计
  15. Fiddler系列教程2:手机抓包图文教程
  16. 2022.01.29
  17. matlab 车身阻尼比曲线,汽车阻尼比及振动响应的分析
  18. 2016奇虎360校园招聘编程题目
  19. 汤唯成了百度地图的“AI算法官” 女神背后靠的就是这些语音技术
  20. Python 数据类型详解(字符串)

热门文章

  1. Jpcap JAVA捕捉并分析网络数据包
  2. SpringCloud微服务架构实战库存管理与分布式文件系统
  3. 前端基础入门之JS 正则表达式
  4. 说一下独享锁/共享锁?
  5. Java AES 加密解密工具类
  6. sps和pps一篇好的解释 H264码流中SPS PPS详解<转>
  7. scuoj 4438 Censor
  8. 从硬件到软件工程师,工作12年,我是如何实现财务自由的
  9. 花卉销售与管理系统的设计与实现
  10. JIGUANG/集光这个小众国货护肤品牌,藏得真是深