"""
根据大json写小json
"""
with open('pay.json') as f:datas = f.readlines()for data in datas:data = data.strip()j = json.loads(data)name = j['content'].split('/')[-1].replace('jpg','json')fw = open('drinks/{}'.format(name),'w')json.dump(j,fw)"""
根据下载好的标注文件转换为txt
"""
for dir in os.listdir('drinks'):datas = json.load(open(os.path.join('drinks',dir)))content = '/home/lixuan/Arduino/hand_detection/landmarks/' + datas['content'].split('/')[-1].split('landmarks_')[-1]annotations = datas['annotation']if annotations == None:print(dir)continue# img = cv2.imread(content)# cv2.imwrite('/home/lixuan/桌面/multicenternetcopy/testimg/{}'.format(datas['content'].split('/')[-1].split('landmarks_')[-1]),img)f = open('/home/lixuan/Arduino/hand_detection/landmarks/' + datas['content'].split('/')[-1].split('landmarks_')[-1].replace('jpg','txt'),'w')# fl = open('train_data/category/' + datas['content'].split('/')[-1].replace('jpg','txt'), 'w')for annotation in annotations:label = '0'#annotation['label'][0]# if label == 'box':#     label = '0'# else:#     label = '1'# if label == '1':# fl.write(label + ' ')points = annotation['points']imageWidth = annotation['imageWidth']imageHeight = annotation['imageHeight']for point in points:point[0] = int(float(point[0]) * imageWidth)point[1] = int(float(point[1]) * imageHeight)points = np.array(points)# points = points[[2, 3, 0, 1], :]#landmark# points = points[[1, 0, 3, 2], :]#92for point in points:f.write(str(point[0]) + ' ' + str(point[1]) + ' ')def func(listTemp, n):for i in range(0, len(listTemp), n):yield listTemp[i:i + n]imglist = []
labellist = []
for dir in os.listdir('/home/lixuan/data/landmarks'):if 'txt' in dir:labellist.append(dir)else:imglist.append(dir)
import cv2
for imgname in imglist:img = cv2.imread('/home/lixuan/data/action/{}'.format(imgname))H,W,_ = img.shapePoint = []with open('/home/lixuan/data/landmarks/{}'.format(imgname.replace('jpg','txt'))) as f:datas = f.readlines()[0].strip().split(' ')#[:-1]for i in range(0, len(datas), 2):b = datas[i:i + 2]Point.append(b)LL = func(Point,4)fw = open('/home/lixuan/data/landmarks/{}'.format(imgname.replace('jpg','txt')),'w')fl = open('/home/lixuan/data/category/{}'.format(imgname.replace('jpg','txt')))for cls in fl.readlines():cls = cls.strip().split(' ')for index,l in enumerate(LL):X = []Y = []for p in l:X.append(int(p[0]))Y.append(int(p[1]))x1 = min(X)y1 = min(Y)x2 = max(X)y2 = max(Y)x = ((x1 + x2) / 2) / Wy = ((y1 + y2) / 2) / Hw = (x2 - x1) / Wh = (y2 - y1) / Hfw.write(cls[index] + ' ' + str(x) + ' ' + str(y) + ' ' + str(w) + ' ' + str(h) + '\n')
import json
import os
import cv2
import numpy as np# for dir in os.listdir('json1'):
#     newname = dir.split('drink1_')[-1]
#     os.system('mv /home/lixuan/centernettrain/json1/{} /home/lixuan/centernettrain/json1/{}'.format(dir,newname))# with open('/home/lixuan/lhq/centernet/train_data/txt标注样列/0ba0e56d-e078-4019-b8d0-74e22fb076ad_3包_40.txt') as f:
#     datas = f.readlines()[0].split(' ')
#     print(len(datas))
#     exit()"""
根据大json写小json
"""
# with open('front_back_shelf_527.json') as f:
#     datas = f.readlines()
#     for data in datas:
#         data = data.strip()
#         j = json.loads(data)
#         name = j['content'].split('/')[-1].replace('jpg','json')
#         fw = open('drinks/{}'.format(name),'w')
#         json.dump(j,fw)
# exit()
"""
根据下载好的标注文件转换为txt
"""
# for dir in os.listdir('json'):
#     datas = json.load(open(os.path.join('json',dir)))
#     content = '/home/lixuan/桌面/landmark/' + datas['content'].split('/')[-1]
#     annotations = datas['annotation']
#     img = cv2.imread(content)
#     cv2.imwrite('train_data/txt标注样列/{}'.format(datas['content'].split('/')[-1]),img)
#     f = open('train_data/txt标注样列/' + datas['content'].split('/')[-1].replace('jpg','txt'),'w')
#     fl = open('train_data/category/' + datas['content'].split('/')[-1].replace('jpg','txt'), 'w')
#     for annotation in annotations:
#         label = annotation['label'][0]
#         if label == 'box':
#             label = '0'
#         else:
#             label = '1'
#         # if label == '1':
#         fl.write(label + ' ')
#         points = annotation['points']
#         imageWidth = annotation['imageWidth']
#         imageHeight = annotation['imageHeight']
#         for point in points:
#             point[0] = int(float(point[0]) * imageWidth)
#             point[1] = int(float(point[1]) * imageHeight)
#         points = np.array(points)
#         # points = points[[2, 3, 0, 1], :]#landmark
#         # points = points[[1, 0, 3, 2], :]#92
#         for point in points:
#             f.write(str(point[0]) + ' ' + str(point[1]) + ' ')"""
bbox
"""
# for dir in os.listdir('drinks'):
#     datas = json.load(open(os.path.join('drinks',dir)))
#     content = '/home/lixuan/fromLX/coco/images/train/' + datas['content'].split('/')[-1]#.split('landmarks_')[-1]
#     annotations = datas['annotation']
#     if annotations == None:
#         print(dir)
#         continue
#     # img = cv2.imread(content)
#     # cv2.imwrite('/home/lixuan/桌面/multicenternetcopy/testimg/{}'.format(datas['content'].split('/')[-1].split('landmarks_')[-1]),img)
#     f = open('/home/lixuan/centernettrain/train_data/txt标注样列/' + datas['content'].split('/')[-1].replace('jpg','txt'),'w')#.split('landmarks_')[-1]
#     fl = open('./cate/' + datas['content'].split('/')[-1].replace('jpg','txt'),'w')
#     for annotation in annotations:
#         label = annotation['label'][0]
#         if label == 'front':
#             label = '1'
#         else:
#             label = '0'
#         # elif label == 'pay':
#         #     label = '1'
#         # elif label == 'handthing':
#         #     label = '2'
#         # elif label == 'handphone':
#         #     label = '3'
#         # elif label == 'handscanning':
#         #     label = '4'
#         # if label == '1':
#         fl.write(label + ' ')
#         points = annotation['points']
#         imageWidth = annotation['imageWidth']
#         imageHeight = annotation['imageHeight']
#         for point in points:
#             point[0] = int(float(point[0]) * imageWidth)
#             point[1] = int(float(point[1]) * imageHeight)
#         points = np.array(points)
#         # points = points[[2, 3, 0, 1], :]#landmark
#         # points = points[[1, 0, 3, 2], :]#92
#         for point in points:
#             f.write(str(point[0]) + ' ' + str(point[1]) + ' ')# for dir in os.listdir('json'):
#     datas = json.load(open(os.path.join('json',dir)))
#     content = '/home/lixuan/lhq/new_wine/' + datas['content'].split('/')[-1]
#     annotations = datas['annotation']
#     # img = cv2.imread(content)
#     # cv2.imwrite('train_data/txt标注样列/{}'.format(datas['content'].split('/')[-1]),img)
#     f = open('train_data/txt标注样列/' + datas['content'].split('/')[-1].replace('jpg','txt'),'w')
#     for annotation in annotations:
#         label = annotation['label'][0]
#         f.write(label + ' ')
#         points = annotation['points']
#         imageWidth = annotation['imageWidth']
#         imageHeight = annotation['imageHeight']
#         for point in points:
#             point[0] = int(float(point[0]) * imageWidth)
#             point[1] = int(float(point[1]) * imageHeight)
#         points = np.array(points)
#         points = points[[2, 3, 0, 1], :]
#         for point in points:
#             f.write(str(point[0]) + ' ' + str(point[1]) + ' ')"""
查看
"""
# imglist = []
# labellist = []
# for dir in os.listdir('/home/lixuan/centernettrain/drinks/txt标注样列'):
#     if 'txt' in dir:
#         labellist.append(dir)
#     else:
#         imglist.append(dir)
# import cv2
# for imgname in imglist:
#     img = cv2.imread('/home/lixuan/centernettrain/drinks/txt标注样列/{}'.format(imgname))
#     Point = []
#     with open('/home/lixuan/centernettrain/drinks/txt标注样列/{}'.format(imgname.replace('jpg','txt'))) as f:
#         datas = f.readlines()[0].strip().split(' ')#[:-1]
#         for i in range(0, len(datas), 2):
#             b = datas[i:i + 2]
#             Point.append(b)
#     for point in Point:
#         img = cv2.circle(img,(int(point[0]),int(point[1])),3,(255,0,0),2)
#         image = cv2.resize(img,(1000,800))
#         cv2.imshow('',image)
#         cv2.waitKey(0)
# print(imglist)
# print(labellist)
"""
bbox
"""def func(listTemp, n):for i in range(0, len(listTemp), n):yield listTemp[i:i + n]imglist = []
labellist = []for dir in os.listdir('drinks'):datas = json.load(open(os.path.join('drinks',dir)))content = datas['content'].split('/')[-1]#.split('landmarks_')[-1]imglist.append(content)labellist.append(content.split('.')[0] + '.txt')# for dir in os.listdir('/home/lixuan/fromLX/coco/images/train'):
#     if 'txt' in dir:
#         labellist.append(dir)
#     else:
#         imglist.append(dir)import cv2
for imgname in imglist:if True:#imgname == '2_img115.jpg':try:img = cv2.imread('/home/lixuan/fromLX/coco/images/train/{}'.format(imgname))H,W,_ = img.shapePoint = []with open('/home/lixuan/centernettrain/train_data/txt标注样列/{}'.format(imgname.replace('jpg','txt'))) as f:datas = f.readlines()[0].strip().split(' ')#[:-1]for i in range(0, len(datas), 2):b = datas[i:i + 2]Point.append([int(x) for x in b])LL = func(Point,4)fw = open('/home/lixuan/centernettrain/train_data/category/{}'.format(imgname.replace('jpg','txt')),'w')fl = open('./cate/{}'.format(imgname.replace('jpg','txt')))for cls in fl.readlines():cls = cls.strip().split(' ')for index,l in enumerate(LL):xs = []ys = []for p in l:xs.append(p[0])ys.append(p[1])x1 = min(xs)y1 = min(ys)x2 = max(xs)y2 = max(ys)x = ((x1 + x2) / 2) / Wy = ((y1 + y2) / 2) / Hw = (x2 - x1) / Wh = (y2 - y1) / Hfw.write(cls[index] + ' ' + str(x) + ' ' + str(y) + ' ' + str(w) + ' ' + str(h) + '\n')# img = cv2.rectangle(img,(int(l[0][0]),int(l[0][1])),(int(l[2][0]),int(l[2][1])),(255,0,0),2)# image = cv2.resize(img,(1000,800))# cv2.imshow('',img)# cv2.waitKey(0)except Exception as e:print(e)
# print(imglist)
# print(labellist)# image = cv2.imread('train_data/txt标注样列/landmark_6.jpg')
# with open('train_data/txt标注样列转为json/annotations/instances.json') as f:
#     Dict = json.load(f)
#     annotations = Dict['annotations']
#     font = cv2.FONT_HERSHEY_SIMPLEX
#     for annotation in annotations:
#         bbox = annotation['bbox']
#         category = annotation['category_id']
#         image = cv2.putText(image, str(category), (bbox[0], bbox[1]), font, 1.2, (255, 0,0), 2)
#     cv2.imwrite('test.jpg',image)# image = cv2.imread('train_data/txt标注样列/landmark_6.jpg')
# with open('train_data/txt标注样列转为json/annotations/instances.json') as f:
#     Dict = json.load(f)
#     annotations = Dict['annotations']
#     font = cv2.FONT_HERSHEY_SIMPLEX
#     for annotation in annotations:
#         segmentation = annotation['segmentation'][0]
#         image = cv2.putText(image, '0', (segmentation[0], segmentation[1]), font, 1.2, (255, 0,0), 2)
#         image = cv2.putText(image, '1', (segmentation[2], segmentation[3]), font, 1.2, (255, 0, 0), 2)
#         image = cv2.putText(image, '2', (segmentation[4], segmentation[5]), font, 1.2, (255, 0, 0), 2)
#         image = cv2.putText(image, '3', (segmentation[6], segmentation[7]), font, 1.2, (255, 0, 0), 2)
#     cv2.imwrite('test.jpg',image)# with open('train_data/txt标注样列转为json/annotations/instances.json') as f:
#     Dict = json.load(f)
#     images = Dict['images']
#     annotations = Dict['annotations']
#     for annotation in annotations:
#         print(annotation)# import os
# base = '/home/lixuan/lhq/centernet/train_data/txt标注样列/landmark_12.txt'
# for i in range(12):
#     os.system('cp {} /home/lixuan/lhq/centernet/train_data/txt标注样列/landmark_{}.txt'.format(base,i))# fw = open('2007_train.txt','w')
# for dir in os.listdir('dd'):
#     with open('dd/' + dir) as f:
#         fw.write(f.read() + '\n')
# from PIL import Image
# imgpath = '/home/lixuan/桌面/json/images/'
# f = open('winelabel.json')
# save_path = '/home/lixuan/lhq/new_wine/'
# for data in f.readlines():
#     data = data.strip()
#     data = json.loads(data)
#     imgname = data['content'].split('wine2/')[-1]
#     img = Image.open(imgpath + imgname)
#     img.save(save_path + imgname)

dataturks解析相关推荐

  1. golang通过RSA算法生成token,go从配置文件中注入密钥文件,go从文件中读取密钥文件,go RSA算法下token生成与解析;go java token共用

    RSA算法 token生成与解析 本文演示两种方式,一种是把密钥文件放在配置文件中,一种是把密钥文件本身放入项目或者容器中. 下面两种的区别在于私钥公钥的初始化, init方法,需要哪种取哪种. 通过 ...

  2. List元素互换,List元素转换下标,Java Collections.swap()方法实例解析

    Java Collections.swap()方法解析 jdk源码: public static void swap(List<?> list, int i, int j) {// ins ...

  3. 条形码?二维码?生成、解析都在这里!

    二维码生成与解析 一.生成二维码 二.解析二维码 三.生成一维码 四.全部的代码 五.pom依赖 直接上代码: 一.生成二维码 public class demo {private static fi ...

  4. Go 学习笔记(82)— Go 第三方库之 viper(解析配置文件、热更新配置文件)

    1. viper 特点 viper 是一个完整的 Go应用程序的配置解决方案,它被设计为在应用程序中工作,并能处理所有类型的配置需求和格式.支持特性功能如下: 设置默认值 读取 JSON.TOML.Y ...

  5. Go 学习笔记(77)— Go 第三方库之 cronexpr(解析 crontab 表达式,定时任务)

    cronexpr 支持的比 Linux 自身的 crontab 更详细,可以精确到秒级别. ​ 1. 实现方式 cronexpr 表达式从前到后的顺序如下所示: 字段类型 是否为必须字段 允许的值 允 ...

  6. mybatis配置文件解析

    mybatis配置文件解析 mybatis核心配置文件`mybatis-config.xml文件. mybatis的配置文件包含了会深深影响mybatis行为的设置和属性信息. 能配置的内容: con ...

  7. 谷歌BERT预训练源码解析(二):模型构建

    版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/weixin_39470744/arti ...

  8. Python 标准库之 xml.etree.ElementTree xml解析

    Python 标准库之 xml.etree.ElementTree Python中有多种xml处理API,常用的有xml.dom.*模块.xml.sax.*模块.xml.parser.expat模块和 ...

  9. 谷歌BERT预训练源码解析(三):训练过程

    目录 前言 源码解析 主函数 自定义模型 遮蔽词预测 下一句预测 规范化数据集 前言 本部分介绍BERT训练过程,BERT模型训练过程是在自己的TPU上进行的,这部分我没做过研究所以不做深入探讨.BE ...

  10. 谷歌BERT预训练源码解析(一):训练数据生成

    目录 预训练源码结构简介 输入输出 源码解析 参数 主函数 创建训练实例 下一句预测&实例生成 随机遮蔽 输出 结果一览 预训练源码结构简介 关于BERT,简单来说,它是一个基于Transfo ...

最新文章

  1. git flow版本
  2. 互联网协议 — TCP — 性能问题解析
  3. AI:2020年6月23日北京智源大会演讲分享之机器学习专题论坛——09:45-10:25邢波教授《A Blueprint of Standardized and Composable ML》
  4. PHP文件系统-文件上传类
  5. Tomcat server.xml配置示例
  6. C++(STL):22 ---序列式容器queue使用
  7. PDX模型不靠谱,土豪来发resource;细菌帮助癌转移,诺奖发现被推翻
  8. Java—基于Fastjson的JSON串序列化和反序列化模板总结
  9. 高通做服务器芯片有优势吗,为什么高通海思联发科不把芯片面积做的和苹果a系列一样大?性能不就赶上了吗?...
  10. Tavas and Karafs 二分+结论
  11. 软件工程的迷途和沉思
  12. Java 文件操作-RandomAccessFile
  13. A 附录、ResolvableType
  14. angular模板加载 ----ng-template
  15. 2017年软件工程第八次作业-互评Alpha版本
  16. mysql passwor authen_Navicat连接虚拟机的MySQL时 提示“Password authentication failed”
  17. 1数字电路设计流程与SOC芯片架构图
  18. css3 3d 太阳系,CSS3实现的太阳系行星系统
  19. 利用计算机来对指纹,指纹自动识别系统.doc
  20. C++ 中调用 Jscript 的函数

热门文章

  1. 在Openwrt 上使用迅雷远程下载功能
  2. 修复YYC松鼠短视频系统搜索功能无法使用问题
  3. Vivado综合running时间太长
  4. MySQL安装教程 + 安装包
  5. MEION:Costas环 环路滤波器参数设置程序
  6. 2020年最新PHP面试题汇总(附答案)
  7. 《西部世界》第三季开播,机器人会比人类更有人性吗?
  8. 【SEO优化,网络营销】刘克亚《利润腾挪》,一分钟销售51000元的书
  9. 《一个人的朝圣》的读后感作文3100字
  10. JavaScript网页编程