Text Region Mask
本系列文章由 @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的更多相关文章
- 【论文速读】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 作 ...
- 论文阅读(Xiang Bai——【arXiv2016】Scene Text Detection via Holistic, Multi-Channel Prediction)
Xiang Bai--[arXiv2016]Scene Text Detection via Holistic, Multi-Channel Prediction 目录 作者和相关链接 方法概括 创新 ...
- 论文阅读(Xiang Bai——【CVPR2015】Symmetry-Based Text Line Detection in Natural Scenes)
Xiang Bai--[CVPR2015]Symmetry-Based Text Line Detection in Natural Scenes 目录 作者和相关链接 方法概括 创新点和贡献 方法细 ...
- 论文速读(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 ...
- 【论文速读】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版代码 关键词 文字 ...
- 【论文速读】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 ...
- 论文阅读(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 ...
- halcon 如何把一个region截取出来保存为图像
read_image(Image,'monkey') gen_circle(region,200,200,150) reduce_domain(Image,region,Mask) crop_doma ...
- Region Normalization for Image Inpainting, AAAI 2020
论文:Region Normalization for Image Inpainting, AAAI 2020 代码:https://github.com/geekyutao/RN 图像修复的目的是重 ...
随机推荐
- sshd_config配置注释
# $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $ # This is the sshd server system-wide c ...
- 运行JavaWeb项目报错Access denied for user 'root'@'localhost' (using password: YES)
问题重现:(以下讨论范围仅限Windows环境): C:\AppServ\MySQL> mysql -u root -p Enter password: ERROR 1045 (28000): ...
- 为DataGridView控件实现复选功能
实现效果: 知识运用: DataGridViewCheckBoxColumn类 实现代码: private class Fruit { public int Price { get; set; } p ...
- openstack nova fail to create vm
2019-05-13 14:43:27.017 47547 ERROR nova.compute.manager [req-3f1af0ed-c342-4cf3-8e76-6963053a5227 8 ...
- 03_6_package和import语句
03_6_package和import语句 1. package和import语句 为便于管理大型软件系统中数目众多的类,解决类的命名冲突问题,Java引入包(package)机制,提供类的多重命名空 ...
- 如何在 JavaScript 中更好地使用数组
使用 Array.includes 替代 Array.indexOf “如果需要在数组中查找某个元素,请使用 Array.indexOf.” 我记得在我学习 JavaScript 的课程中有类似的这么 ...
- [bzoj]3436 小K的农场
[题目描述] 小K在MC里面建立很多很多的农场,总共n个,以至于他自己都忘记了每个农场中种植作物的具体数量了,他只记得一些含糊的信息(共m个),以下列三种形式描述:农场a比农场b至少多种植了c个单位的 ...
- C语言程序运行
vs2013编辑器 c程序的运行 一.启动Microsoft Visual C++ 2013版.新建项目 . 1. 文件——> 新建——> 项目. 2. 确定之后 弹出 ...
- Oracle 数据库常用SQL语句(2)查询语句
一.SQL基础查询 1.select语句 格式:select 字段 from 表名; 2.where 用于限制查询的结果. 3.查询条件 > < >= <= = != 4.与 ...
- OC8051项目启动