代码拉取完成,页面将自动刷新
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)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。