加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
util-drawpic_withtxt.py 1.56 KB
一键复制 编辑 原始数据 按行查看 历史
椰子奶糖 提交于 2022-03-31 10:07 . init
import cv2
import numpy as np
import os
dir_img = "../data/images/"
dir_txt = "model/ship_gt/labels_withoutname/"
save_dir = os.path.dirname(os.path.dirname(dir_img)) + '/show_pt/'
if not os.path.exists(save_dir):
os.makedirs(save_dir)
# import pdb
# pdb.set_trace()
def deal_txt_pt(path_txt):
lll_pt = []
with open(path_txt, 'r') as fr:
for line in fr.readlines():
ll_pt = []
line = line.strip()
list_num = line.split(',')
l_pt = []
for cnt, num in enumerate(list_num):
num = float(num)
l_pt.append(num)
if 2 == len(l_pt):
ll_pt.append(l_pt)
l_pt = []
lll_pt.append(ll_pt)
return lll_pt
list_img = os.listdir(dir_img)
label_num = [0,0,0,0,0,0]
_classes = {'__background__':0,'cg':1,'cvn':2,'ddg':3,'lcc':4,'render':5}
# import pdb
# pdb.set_trace()
for cnt,img_name in enumerate(list_img):
print("cnt=%d,img_name=%s"%(cnt,img_name))
# txt_name = img_name.replace('.jpg','.txt')
txt_name = img_name.replace('.png','.txt')
label_num[_classes[txt_name.split('_')[0].lower().strip()]]+=1
# path_img = dir_img + img_name
# path_txt = dir_txt + txt_name
# save_path = save_dir + img_name
# img = cv2.imread(path_img)
# lll_pt = deal_txt_pt(path_txt)
# for ll_pt in lll_pt:
# pts = np.array(ll_pt,np.int32)
# pts = pts.reshape((-1, 1, 2))
# cv2.polylines(img, [pts], 1, (0, 255, 255),2)
# cv2.imwrite(save_path,img)
print(label_num)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化