使用前注意:如果标注前需要对图片尺寸进行修改,务必先修改图片尺寸,再标注

"""
修改图片尺寸的代码
"""
from PIL import Image
import osFiles_path = r"C:\Users\dd\Desktop\标注远距离图片"  # C:\Users\dd\Desktop\标注远距离图片\data  注意图片是放在data文件夹下的!!!
labels_num = len(os.listdir(Files_path))
print(labels_num)for i in range(labels_num):image_dir = os.path.join(Files_path, str(os.listdir(Files_path)[i]))print(image_dir)image_list = os.listdir(image_dir)for image_name in image_list:image_path = os.path.join(image_dir, image_name)img = Image.open(image_path)print(img)x_s = 512y_s = 512Resize_image = img.resize((x_s, y_s), Image.ANTIALIAS)Resize_out_path = r"C:\Users\dd\Desktop\标注远距离图片"Resize_image.save(Resize_out_path + '/' + str(os.listdir(Files_path)[i]) + '/' + str(image_name))

1.按照下图中流程标注:

(下面的图片顶端的路径调整一下,C:\Users\dd\Desktop\标注远距离图片\left_0.jpg 变为 C:\Users\dd\Desktop\标注远距离图片\data\left_0.jpg)




2.处理标注后的json文件

2.1 修改json_to_dataset.py文件的内容:(如果已经替换过则忽略)

参考链接
在D:\Anaconda\envs\labelme\Lib\site-packages\labelme\cli 可以看到json_to_dataset.py文件
修改为:

import argparse
import json
import os
import os.path as osp
import warningsimport PIL.Image
import yamlfrom labelme import utils
import base64def main():warnings.warn("This script is aimed to demonstrate how to convert the\n""JSON file to a single image dataset, and not to handle\n""multiple JSON files to generate a real-use dataset.")parser = argparse.ArgumentParser()parser.add_argument('json_file')parser.add_argument('-o', '--out', default=None)args = parser.parse_args()json_file = args.json_fileif args.out is None:out_dir = osp.basename(json_file).replace('.', '_')out_dir = osp.join(osp.dirname(json_file), out_dir)else:out_dir = args.outif not osp.exists(out_dir):os.mkdir(out_dir)count = os.listdir(json_file) for i in range(0, len(count)):path = os.path.join(json_file, count[i])if os.path.isfile(path):data = json.load(open(path))if data['imageData']:imageData = data['imageData']else:imagePath = os.path.join(os.path.dirname(path), data['imagePath'])with open(imagePath, 'rb') as f:imageData = f.read()imageData = base64.b64encode(imageData).decode('utf-8')img = utils.img_b64_to_arr(imageData)label_name_to_value = {'_background_': 0}for shape in data['shapes']:label_name = shape['label']if label_name in label_name_to_value:label_value = label_name_to_value[label_name]else:label_value = len(label_name_to_value)label_name_to_value[label_name] = label_value# label_values must be denselabel_values, label_names = [], []for ln, lv in sorted(label_name_to_value.items(), key=lambda x: x[1]):label_values.append(lv)label_names.append(ln)assert label_values == list(range(len(label_values)))lbl = utils.shapes_to_label(img.shape, data['shapes'], label_name_to_value)captions = ['{}: {}'.format(lv, ln)for ln, lv in label_name_to_value.items()]lbl_viz = utils.draw_label(lbl, img, captions)out_dir = osp.basename(count[i]).replace('.', '_')out_dir = osp.join(osp.dirname(count[i]), out_dir)if not osp.exists(out_dir):os.mkdir(out_dir)PIL.Image.fromarray(img).save(osp.join(out_dir, 'img.png'))#PIL.Image.fromarray(lbl).save(osp.join(out_dir, 'label.png'))utils.lblsave(osp.join(out_dir, 'label.png'), lbl)PIL.Image.fromarray(lbl_viz).save(osp.join(out_dir, 'label_viz.png'))with open(osp.join(out_dir, 'label_names.txt'), 'w') as f:for lbl_name in label_names:f.write(lbl_name + '\n')warnings.warn('info.yaml is being replaced by label_names.txt')info = dict(label_names=label_names)with open(osp.join(out_dir, 'info.yaml'), 'w') as f:yaml.safe_dump(info, f, default_flow_style=False)print('Saved to: %s' % out_dir)
if __name__ == '__main__':main()

2.2 处理json文件

命令行输入:

F:\>cd F:\Anaconda\Scripts
F:\Anaconda\Scripts>labelme_json_to_dataset.exe C:\Users\dd\Desktop\标注远距离图片\标注后文件


3.使用Python批量提取不同json文件夹中的img.png 和 label.png图片:

3.1 如果json文件夹的命名各不相同,为了提取方便,先使用Python批量修改一个文件夹下所有文件夹的名字,这里统一改成了rgb_i_json,其中i从1到n,代码如下:

import os
dirs = os.listdir(r'C:\Users\dd\Desktop\标注远距离图片\json_to_data')
i = 1
for dir in dirs:# 获取每个文件夹print(dir)# 获取文件夹的名字oldName = os.path.join(r'C:\Users\dd\Desktop\标注远距离图片\json_to_data', dir)newName = os.path.join(r'C:\Users\dd\Desktop\标注远距离图片\json_to_data', 'rgb_'+str(i)+'_json')# 执行修改名称的方法.参数1告诉他以前的名字叫啥;参数2告诉他新名字叫啥os.rename(oldName, newName)i += 1

3.2 然后,分别提取rgb_i_json文件夹中的各个img.png和label.png到两个新的文件夹中,代码如下:

import os
import shutilpath = input('_json文件夹所在的路径:')
new_path = input('需保存的路径:')
count = os.listdir(path)
for j in range(1, len(count) + 1):for root, dirs, files in os.walk(path):if len(dirs) == 0:for i in range(len(files)):print("i=", i)# 样例:# if files[i].find('label.png') != -1:#     shutil.copy(os.path.join(path + '/rgb_' + str(j).zfill(4) + '_json/', files[i]),#                 os.path.join(new_path, 'rgb_' + str(j).zfill(4) + '.png'))# 将label.png提取出来并且按照顺序命名1.png....if files[i].find('label.png') != -1:shutil.copy(os.path.join(path + '/rgb_' + str(j).zfill(1) + '_json/', files[i]),os.path.join(new_path, str(j).zfill(1) + '.png'))# 将img.png提取出来并且按照顺序命名1.png.....# if files[i].find('img.png') != -1:#     shutil.copy(os.path.join(path + '/rgb_' + str(j).zfill(1) + '_json/', files[i]),#                 os.path.join(new_path, str(j).zfill(1) + '.png'))

Labelme标注流程相关推荐

  1. 2021-07-27 对labelme标注出来的JSON文件进行灰度图转化(标签值0.1.2.3.4)

    对labelme标注出来的JSON文件进行灰度图转化(标签值0.1.2.3.4) 原图如下: 标注后生成json文件如下: import cv2 import numpy as np import j ...

  2. labelme标注文件转coco json,coco json转yolo txt格式,coco json转xml, labelme标注文件转分割,boxes转labelme json

    参考:https://github.com/wkentaro/labelme 一.labelme标注文件转coco json 1.标注时带图片ImageData信息,将一个文件夹下的照片和labelm ...

  3. LabelMe标注的.json文件批量转Dataset,通过查询到多种代码无法在我电脑上正常工作,发现他们有共同的报错,于是修改后能正常工作。

    1.写在前面 最近用到标注好的数据训练神经网络,用labelme标注好之后生成.json文件,我要实现的功能是目标分割,需要把.json文件转为VOC格式的数据.但是.json文件太多,于是在网上找一 ...

  4. labelme 标注生成24位深度图像转换为8位

    新版本的 labelme 标注完成图像后,将 json 文件转换为图像时已经转换为 8 通道图像,如下图所示: 最近在看别人程序时发现经过图像标注生成的 label 一片黑,且图像深度为 24 位,如 ...

  5. Labelme标注的json数据转化为coco格式的数据

    Labelme标注的json数据转化为coco格式的数据 1. 转化方法一 2. 转化方法二 1. 转化方法一 import os import json import numpy as np imp ...

  6. labelme标注结果可视化(持续补充)

    图像数据常用的标注工具是labelme,标注的格式是json.labelme标注结果可视化,是将标注结果绘制到原始图像上,以方便查看标注结果. 1 json文件读取与保存 由于labelme标注的保存 ...

  7. python脚本对labelme标注的数据集进行镜面旋转扩充数据集

    使用labelme做数据集标注效率不得不说非常感人,由此开始思考如何利用已经标注的数据集 参考如下脚本 编写python脚本对labelme标注的数据集进行左右/上下镜面翻转扩充数据集_Alex-Le ...

  8. 使用labelme标注语义分割数据

    当我们从各种途径获得图片数据之后,需要对其进行分割标注. 这里我们使用labelme标注工具. 环境: anaconda3 labelme项目地址:https://github.com/wkentar ...

  9. labelme标注的json标签转txt格式

    在机器学习训练中常常会有不同格式的标签之间的转换,本次是将json标签格式转化成txt格式,在此记录一下. 1.labelme标注: 2.json文件: {"version": & ...

最新文章

  1. python tk text scrollbar_tk.Scrollbar控件的使用
  2. Windows安装MongoDB
  3. 16进制加法 keil_教你快速学会二进制、十进制、十六进制之间的转换
  4. Stanford UFLDL教程 神经网络向量化
  5. 线性代数可以速成吗_英语真的可以速成吗?
  6. gtest 测试java_LangTest
  7. python socket编程_Python学习记录-socket编程
  8. 如何关掉Microsoft Office Click-to-Run服务
  9. html-简单验证、滑块、搜索框
  10. GitHub 标星 10,000+,Apache 顶级项目 ShardingSphere 的开源之路
  11. Zigbee 协议栈网络管理
  12. 计算机网络英文题库(含答案) Chapter 1 Computer Networks and the Internet
  13. 一项研究调查了采用Masimo Rad-G™搭配RRp(R)实现自动呼吸频率测量的影响
  14. 易扩展,易复用,封装axios
  15. 鼠标手--IT人士/电脑使用者、网民的职业病,给网友们提个醒
  16. 对抗样本论文学习:Deep Neural Networks are Easily Fooled
  17. FAERIE QVEENE 仙后节选
  18. python打开图片文件-Python怎么读取图片
  19. DZ克米模板论坛V3.5版+全解密/全插件/教程
  20. PS透视模型动作插件:Perspective Mockups mac(支持ps2021)

热门文章

  1. SWMM排水管网水力、水质建模及在海绵城市与水环境保护中的应用
  2. python 微信机器人教程_Python创建微信机器人(附赠Python视频教程)
  3. Teredo tunneling pseudo-interface前面有个黄色感叹号
  4. 苹果手机上运行python_手机上运行Python
  5. 暗影精灵双系统(win10和Ubuntu16.04)安装+Cuda和tensorflow安装-深度学习环境配置
  6. ENVI:标准库中光谱(.sli)重采样
  7. Centos下samba共享打印机
  8. WhbtomT(半路出家) 的每日英语 收集 (四)
  9. 第6章 PPT页面排版与高级设计技术
  10. pr基本图形模板无法使用_辣么美的PR基本图形模板,不能改字体怎么办