1:安装labelme (可百度,最好安在虚拟环境)
2:cmd 到图片上层文件夹,在终端激活labelme环境,然后直接输入labelme打开labelme标注工具
3:opendir-图片文件夹选择保村json的文件夹
4:选择点,线,区域进行标注
如果有两种区域或者两条线路则不同区域线路的名字区别一下
5:标注完成后生产n(图片个数)个json
6:在json文件夹下运行批处理文件:
@echo off
activate labelme & for %%i in (*.json) do labelme_json_to_dataset "%%i"
pause
生产单个json文件夹:
内部:4
yaml文件新的labelme都没有了似乎没有用这个,如果想用更改labelme下
# 后部分加上生成".yaml"文件的部分 一定注意位置
logger.warning('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)
7:利用data.py
import cv2
from skimage import measure, color
from skimage.measure import regionprops
import numpy as np
import os
import copy
def skimageFilter(gray):
binary_warped = copy.copy(gray)
binary_warped[binary_warped > 0.1] = 255
gray = (np.dstack((gray, gray, gray))*255).astype('uint8')
labels = measure.label(gray[:, :, 0], connectivity=1)
dst = color.label2rgb(labels,bg_label=0, bg_color=(0,0,0))
gray = cv2.cvtColor(np.uint8(dst*255), cv2.COLOR_RGB2GRAY)
return binary_warped, gray
def moveImageTodir(path,targetPath,name):
if os.path.isdir(path):
image_name = "gt_image/"+str(name)+".png"
binary_name = "gt_binary_image/"+str(name)+".png"
instance_name = "gt_instance_image/"+str(name)+".png"
train_rows = image_name + " " + binary_name + " " + instance_name + "\n"
origin_img = cv2.imread(path+"/img.png")
origin_img = cv2.resize(origin_img, (1280,720))
cv2.imwrite(targetPath+"/"+image_name, origin_img)
img = cv2.imread(path+'/label.png')
img = cv2.resize(img, (1280,720))
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
binary_warped, instance = skimageFilter(gray)
cv2.imwrite(targetPath+"/"+binary_name, binary_warped)
cv2.imwrite(targetPath+"/"+instance_name, instance)
print("success create data name is : ", train_rows)
return train_rows
return None
if __name__ == "__main__":
count = 1
with open("./train.txt", 'w+') as file:
for images_dir in os.listdir("./images"):
dir_name = os.path.join("./images", images_dir + "/annotations")
for annotations_dir in os.listdir(dir_name):
json_dir = os.path.join(dir_name, annotations_dir)
if os.path.isdir(json_dir):
train_rows = moveImageTodir(json_dir, "./", str(count).zfill(4))
file.write(train_rows)
count += 1
获得gt----,三个文件夹和train.txt,需要自己建立,在运行之前需要把第6步生成的json多有文件夹,放在images/data/annotations/下面,这样不用改data.py 的程序直接用。