加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
util-drawpic_icdar.py 1.62 KB
一键复制 编辑 原始数据 按行查看 历史
椰子奶糖 提交于 2022-03-31 10:07 . init
import cv2
import numpy as np
import os
# ground truth directory
# original images directory
# image_dir = "/code/text_location/training_data/images/"
dir_img = "/code/text_location/training_data/images/"
# gt_text_dir = "/code/text_location/training_data/labels/"
dir_txt = "/code/text_location/training_data/labels/"
# imgs_save_dir = "/code/text_location/training_data/draw_pics"
save_dir = "/code/text_location/training_data/draw_pics"
if not os.path.exists(save_dir):
os.makedirs(save_dir)
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)
# 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')
import pdb
pdb.set_trace()
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)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化