• Stars
    star
    185
  • Rank 207,019 (Top 5 %)
  • Language
    Python
  • License
    MIT License
  • Created about 2 years ago
  • Updated 5 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

通过浏览器渲染生成表格图像

TableGeneration

通过浏览器渲染生成表格图像,代码修改自论文 Rethinking Table Parsing using Graph Neural Networks 源代码

修改后主要特性如下:

  1. 支持更多参数可配置,如单元格类型,表格行列,合并单元格数量,
  2. 支持彩色单元格
  3. 内置四种类型表格,如下表所示
类型 样例
简单表格
彩色表格
清单表格
大单元格表格

环境准备

安装python包

pip3 install -r requirements.txt

目前支持使用chrome浏览器和火狐浏览器,使用方式分别如下

chrome浏览器(Linux下推荐)

  • 安装chrome浏览器和中文字体
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome-stable_current_amd64.deb
apt-get update && sudo apt-get install libnss3
apt-get install xfonts-wqy
apt install ttf-wqy-zenhei
apt install fonts-wqy-microhei
# refresh fonts
fc-cache -fv
  • 安装chrome浏览器驱动 chromedriver

首先在官网下载适合自己系统的驱动文件。然后执行下列命令

unzip chromedriver_linux64.zip
cp chromedriver /usr/local/share/
ln -s /usr/local/share/chromedriver /usr/local/bin/chromedriver
ln -s /usr/local/share/chromedriver /usr/bin/chromedriver
  • 测试浏览器和chromedriver

使用如下命令测试chromedriver和chrome浏览器是否安装正确

from selenium import webdriver

options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
driver = webdriver.Chrome(chrome_options=options)
driver.get('https:www.baidu.com')
print(driver.title)
driver.close()

如果成功,会在终端看见如下输出

百度一下,你就知道

火狐浏览器(Mac下推荐)

  • 安装火狐浏览器和中文字体
apt-get -y install firefox
apt-get install xfonts-wqy
apt install ttf-wqy-zenhei
apt install fonts-wqy-microhei
# refresh fonts
fc-cache -fv
  • 安装火狐浏览器驱动 geckodriver

首先在官网下载适合自己系统的驱动文件。然后执行下列命令

tar -xf geckodriver-v0.31.0-linux64.tar.gz
cp geckodriver /usr/local/share/
ln -s /usr/local/share/geckodriver /usr/local/bin/geckodriver
ln -s /usr/local/share/geckodriver /usr/bin/geckodriver
  • 测试浏览器和geckodriver

使用如下命令测试geckodriver和火狐是否安装正确

from selenium import webdriver

options = webdriver.FirefoxOptions()
options.add_argument('--headless')
driver = webdriver.Firefox(firefox_options=options)
driver.get('https:www.baidu.com')
print(driver.title)
driver.close()

如果成功,会在终端看见如下输出

百度一下,你就知道

生成表格

生成表格

使用如下命令可生成表格,ch_dict_pathen_dict_path 不指定时,将会使用默认的中英文语料。最终生成的表格图片,表格html文件和PP-Structure格式标注文件会保存在output指定路径下。

# 简单表格
python3 generate_data.py --output output/simple_table --num=1
# 单元格坐标为单元格内文字坐标的表格
python3 generate_data.py --output output/simple_table --num=1 --cell_box_type='text'
# 彩色单元格表格
python3 generate_data.py --output output/color_simple_table --num=1 --color_prob=0.3
# 清单类表格
python3 generate_data.py --output output/qd_table --num=1 --min_row=10 --max_row=80 --min_col=4 --max_col=8 --min_txt_len=2 --max_txt_len=10 --max_span_row_count=3 --max_span_col_count=3 --max_span_value=20 --color_prob=0 --brower_width=1920 --brower_height=5000
# 大单元格表格
python3 generate_data.py --output output/big_cell_table --num=1 --min_row=6 --max_row=10 --min_col=4 --max_col=8 --min_txt_len=2 --max_txt_len=10 --max_span_row_count=3 --max_span_col_count=3 --max_span_value=10 --color_prob=0 --cell_max_width=100 --cell_max_height=100 --brower_width=1920 --brower_height=1920

校验数据

使用如下命令即可对生成的数据进行校验:

python3 vis_gt.py --image_dir path/to/imgs --gt_path path/to/gt.txt

这个命令会生成一个html页面,在html页面中会展示图片名、原图、表格的可视化和cell坐标。如下所示:

类型 样例
cell坐标为单元格内文字坐标
cell坐标为真实单元格坐标

表格生成流程:

  1. 随机生成表格行列
  2. 随机生成表格合并单元格数量和合并的起始结束位置
  3. 对于每一个单元格随机生成文本并组合成html字符串
  4. 使用浏览器对html字符串进行渲染生成表格图片
  5. 浏览器截图获取表格图片
  6. 裁剪图片,只保留表格区域
  7. 保存PP-Structure标注格式

More Repositories

1

PytorchOCR

基于Pytorch的OCR工具库,支持常用的文字检测和识别算法
Python
1,345
star
2

DBNet.pytorch

A pytorch re-implementation of Real-time Scene Text Detection with Differentiable Binarization
Python
939
star
3

OCR_DataSet

收集并整理有关OCR的数据集并统一标注格式,以便实验需要
Python
856
star
4

PSENet.pytorch

A pytorch re-implementation of PSENet: Shape Robust Text Detection with Progressive Scale Expansion Network
C++
462
star
5

PAN.pytorch

A unofficial pytorch implementation of PAN(PSENet2): Efficient and Accurate Arbitrary-Shaped Text Detection with Pixel Aggregation Network
C++
413
star
6

flask_pytorch

using flask to run pytorch model
Python
48
star
7

crnn.gluon

A gluon re-implementation of Convolutional recurrent network in gluon
Python
21
star
8

reprod_log

Python
16
star
9

Segmentation-Free_OCR

recognize chinese and english without segmentation
Python
11
star
10

Torch_Quant_Demo

一个使用torch进行量化训练的demo
Python
9
star
11

ctpn.pytorch

Python
9
star
12

crypto

Python
7
star
13

dl_docker

用于深度学习的docker环境,cuda支持cuda10.1和cuda10.2,框架支持各种框架
Dockerfile
6
star
14

IcdarToCOCO

Python
5
star
15

gluon_mnist

learning gluon with mnist dataset
Python
5
star
16

mxnet_cifar10

Python
4
star
17

crnn.paddle

Python
4
star
18

leetcode

learning data struct with python
Jupyter Notebook
4
star
19

UCDIR.paddle

Python
4
star
20

TableMASTER_mmocr

Python
3
star
21

rust_python

use rust speed up python
Rust
3
star
22

pytorch_mnist

learning pytorch with mnist dataset
Python
3
star
23

WenmuZhou.github.io

个人博客
HTML
2
star
24

keras_mnist

learning keras with mnist
Python
2
star
25

gitment-comments

2
star
26

DABNet_Paddle

a paddle reproduce of DABNet
Python
1
star
27

simple_nlp

Python
1
star