本系列文章由 @yhl_leo 出品,转载请注明出处。

文章链接: http://blog.csdn.net/yhl_leo/article/details/52886351


Python code : yhlleo/textRegionMask


根据图像中文本字符的坐标信息,生成文本区域mask图像。如下图

文本字符信息记录格式为:

bjtextset01_0004.jpg
1
1 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 os
import copy as cp class DataGt(object):
"""docstring for DataGt"""
def __init__(self, fname, trlist):
super(DataGt, self).__init__()
self.fname = fname
self.trlist = trlist def 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 os
import cv2
import loadgt
import numpy as np def im_lists( path ):
return os.listdir(path); def path_insensitive(lst, fn):
for ln in lst:
if ln.lower() == fn.lower():
return ln
return None def 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

Text Region Mask的更多相关文章

  1. 【论文速读】Shangbang Long_ECCV2018_TextSnake_A Flexible Representation for Detecting Text of Arbitrary Shapes

    Shangbang Long_ECCV2018_TextSnake_A Flexible Representation for Detecting Text of Arbitrary Shapes 作 ...

  2. 论文阅读(Xiang Bai——【arXiv2016】Scene Text Detection via Holistic, Multi-Channel Prediction)

    Xiang Bai--[arXiv2016]Scene Text Detection via Holistic, Multi-Channel Prediction 目录 作者和相关链接 方法概括 创新 ...

  3. 论文阅读(Xiang Bai——【CVPR2015】Symmetry-Based Text Line Detection in Natural Scenes)

    Xiang Bai--[CVPR2015]Symmetry-Based Text Line Detection in Natural Scenes 目录 作者和相关链接 方法概括 创新点和贡献 方法细 ...

  4. 论文速读(Chuhui Xue——【arxiv2019】MSR_Multi-Scale Shape Regression for Scene Text Detection)

    Chuhui Xue--[arxiv2019]MSR_Multi-Scale Shape Regression for Scene Text Detection 论文 Chuhui Xue--[arx ...

  5. 【论文速读】Yuliang Liu_2017_Detecting Curve Text in the Wild_New Dataset and New Solution

    Yuliang Liu_2017_Detecting Curve Text in the Wild_New Dataset and New Solution 作者和代码 caffe版代码 关键词 文字 ...

  6. 【论文速读】Chuhui Xue_ECCV2018_Accurate Scene Text Detection through Border Semantics Awareness and Bootstrapping

    Chuhui Xue_ECCV2018_Accurate Scene Text Detection through Border Semantics Awareness and Bootstrappi ...

  7. 论文阅读(Weilin Huang——【arXiv2016】Accurate Text Localization in Natural Image with Cascaded Convolutional Text Network)

    Weilin Huang——[arXiv2016]Accurate Text Localization in Natural Image with Cascaded Convolutional Tex ...

  8. halcon 如何把一个region截取出来保存为图像

    read_image(Image,'monkey') gen_circle(region,200,200,150) reduce_domain(Image,region,Mask) crop_doma ...

  9. Region Normalization for Image Inpainting, AAAI 2020

    论文:Region Normalization for Image Inpainting, AAAI 2020 代码:https://github.com/geekyutao/RN 图像修复的目的是重 ...

随机推荐

  1. reactnative资源

    http://facebook.github.io/react-native/docs/getting-started.html

  2. <转>Spring 知识点提炼

    Spring 知识点提炼 1. Spring框架的作用 轻量:Spring是轻量级的,基本的版本大小为2MB 控制反转:Spring通过控制反转实现了松散耦合,对象们给出它们的依赖,而不是创建或查找依 ...

  3. Caused by: java.lang.IllegalStateException: javax.websocket.server.ServerContainer not available

    java.lang.IllegalStateException: Failed to load ApplicationContext    at org.springframework.test.co ...

  4. BZOJ 3130: [Sdoi2013]费用流 网络流+二分

    3130: [Sdoi2013]费用流 Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 1230  Solved: ...

  5. 【UML】协作图Collaboration diagram(交互图)(转)

    http://blog.csdn.net/sds15732622190/article/details/49402269 前言         学完UML时序图,就要看一下UML协作图,因为两张图是相 ...

  6. [dp uestc oj] G - 邱老师玩游戏

    G - 邱老师玩游戏 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  7. CentOS安装RabbitMQ步骤

    1.安装gcc yum install gcc 安装 ncurses-devel yum install ncurses-devel 2.安装erlang 下载安装包 http://www.erlan ...

  8. 《毛毛虫组》【Alpha】Scrum meeting 4

    第二天 日期:2019/6/17 1.1 今日完成任务情况以及遇到的问题. 今日完成任务情况: 货物入库管理模块设计: (1)对数据库表--tb_OutStore进行修改并完善: (2)学习trig_ ...

  9. Spring XML配置文件无法自动提示 eclipse中XML配置文件open with打开方式选择 XML Editor:注意它的编辑方式也是有两种的design和source

    双击XML配置文件,如果打开方式不正确 则如下图: 都是灰色显示,不会有自动提示,也不会有颜色标注 右击XML配置文件,选择打开方式为XML Editor,则会有颜色标注 如果此时没有自动提示 则要手 ...

  10. VMware安装Ubuntu配置NAT模式下静态IP,解决访问外网问题

    安装好VMware后,打开网络连接可以看到有VMware Network Adapter VMnet1和VMware Network Adapter VMnet8两个网络适配器,VMnet1是针对桥接 ...