Text Region Mask
来源:互联网 发布:浙江软件协会 编辑:程序博客网 时间:2024/06/08 16:44
本系列文章由 @yhl_leo 出品,转载请注明出处。
文章链接: http://blog.csdn.net/yhl_leo/article/details/52886351
Python code : yhlleo/textRegionMask
根据图像中文本字符的坐标信息,生成文本区域mask图像。如下图
文本字符信息记录格式为:
bjtextset01_0004.jpg11 527.50 243.50 581.67 311.00 "2"
其中,bjtextset01_0004.jpg
为图像名(全小写字符),紧接着的1
为包含文本字符的数量,后面接着就是对应的文本字符的位置坐标527.50 243.50 581.67 311.00
(格式为x, y, x, y
,即两个顶点坐标),2
为字符内容,该行最前面的1
为标记符,可以忽略。
首先,读取文本内容:
import osimport copy as cpclass DataGt(object): """docstring for DataGt""" def __init__(self, fname, trlist): super(DataGt, self).__init__() self.fname = fname self.trlist = trlistdef loaddata(path): fp = open(path).read().splitlines() gt = DataGt([],[]) niter = 0 idx = 0 while niter < len(fp): if '.jpg' in fp[idx]: textlst = [] gt.fname.append(fp[idx]); idx = idx + 1 num = int(fp[idx]) for i in range(num): idx = idx + 1 if '1' in fp[idx] and '\"' in fp[idx]: loc = fp[idx].split(' ')[1:5] textlst.append(loc) gt.trlist.append(textlst) else: idx = idx + 1 niter = idx return gt
然后,绘制mask图:
import osimport cv2import loadgtimport numpy as npdef im_lists( path ): return os.listdir(path);def path_insensitive(lst, fn): for ln in lst: if ln.lower() == fn.lower(): return ln return Nonedef genMask(gt, im_path, savepath): num = len(gt.fname) ims = im_lists(im_path) for idx in range(num): fn = path_insensitive( ims, gt.fname[idx] ) fname = os.path.join(im_path, fn) sname = os.path.join(savepath, fn) im = cv2.imread(fname) size_im = im.shape #print size_im mask = np.zeros([size_im[0], size_im[1]], dtype=np.uint8) for ls in gt.trlist[idx]: mask[int(float(ls[1])):int(float(ls[3])), int(float(ls[0])): int(float(ls[2]))] = 255 cv2.imwrite(sname, mask, [cv2.cv.CV_IMWRITE_PNG_COMPRESSION, 0])im_path = "./data"savepath = "./mask"gtpath = "./test.txt"gt = loadgt.loaddata(gtpath)genMask(gt,im_path, savepath)
结果如图: Image TextRegionMask
1 0
- Text Region Mask
- find text region in ppt
- mask
- mask
- Mask
- ffmpeg command use one command : logo, text, mask, audio process
- Unity UI(四):Text、Image/RawImage和Mask
- region
- Region
- #region
- Region-based Discriminative feature pooling for scene text recognition (CVPR14)
- css属性background-attachment,box-reflect,text-stroke,mask,margin-collapse
- 编译时提示`.text' will not fit in region `iram1_0_seg' 解决方式
- 【论文笔记】 R2CNN: Rotational Region CNN for Orientation Robust Scene Text Detection
- arm-none-eabi/bin/ld: build/com.zubax.gnss.elf section `.text' will not fit in region `flash'
- tooltip , mask
- subnet Mask
- Screen Mask
- httpclient 多线程高并发Get请求
- TensorFlow学习笔记(四)——TensorFlow运作方式入门、可视化
- Spark企业级环境搭建
- JS实现图片的延迟加载
- easyui tree 获取树的深度
- Text Region Mask
- 图像配准方面的算法总结
- 指针数组和数组指针的使用
- Python:UnicodeEncodeError:'ascii' codec can't encode/decode characters
- BZOJ 3323: [Scoi2013]多项式的运算【平衡树
- 【codeforces 297 C Splitting the Uniqueness】+ 数组构造
- ORACLE存储函数讲解
- 指示器Demo
- JAVA安卓植物大战僵尸主题四子棋游戏