Skip to content

Commit

Permalink
add img show code
Browse files Browse the repository at this point in the history
  • Loading branch information
WenmuZhou committed Aug 1, 2021
1 parent eb9e355 commit bec6ab0
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Binary file added doc/table/layout.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions ppstructure/layout/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pip install -U https://paddleocr.bj.bcebos.com/whl/layoutparser-0.0.0-py3-none-a
```python
import cv2
import layoutparser as lp
image = cv2.imread("imags/paper-image.jpg")
image = cv2.imread("doc/table/layout.png")
image = image[..., ::-1]

# 加载模型
Expand All @@ -39,7 +39,8 @@ model = lp.PaddleDetectionLayoutModel(config_path="lp:https://PubLayNet/ppyolov2_r50vd
layout = model.detect(image)

# 显示结果
lp.draw_box(image, layout, box_width=3, show_element_type=True)
show_img = lp.draw_box(image, layout, box_width=3, show_element_type=True)
show_img.show()
```

下图展示了结果,不同颜色的检测框表示不同的类别,并通过`show_element_type`在框的左上角显示具体类别:
Expand Down Expand Up @@ -80,6 +81,7 @@ lp.draw_box(image, layout, box_width=3, show_element_type=True)
版面分析检测包含多个类别,如果只想获取指定类别(如"Text"类别)的检测框、可以使用下述代码:

```python
# 接上面代码
# 首先过滤特定文本类型的区域
text_blocks = lp.Layout([b for b in layout if b.type=='Text'])
figure_blocks = lp.Layout([b for b in layout if b.type=='Figure'])
Expand All @@ -103,9 +105,10 @@ right_blocks.sort(key = lambda b:b.coordinates[1])
text_blocks = lp.Layout([b.set(id = idx) for idx, b in enumerate(left_blocks + right_blocks)])

# 显示结果
lp.draw_box(image, text_blocks,
show_img = lp.draw_box(image, text_blocks,
box_width=3,
show_element_id=True)
show_img.show()
```

显示只有"Text"类别的结果:
Expand Down
10 changes: 7 additions & 3 deletions ppstructure/layout/README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ pip install -U layoutparser-0.0.0-py3-none-any.whl
Use LayoutParser to identify the layout of a given document:

```python
import cv2
import layoutparser as lp
image = cv2.imread("imags/paper-image.jpg")
image = cv2.imread("doc/table/layout.png")
image = image[..., ::-1]

# load model
Expand All @@ -39,7 +40,8 @@ model = lp.PaddleDetectionLayoutModel(config_path="lp:https://PubLayNet/ppyolov2_r50vd
layout = model.detect(image)

# show result
lp.draw_box(image, layout, box_width=3, show_element_type=True)
show_img = lp.draw_box(image, layout, box_width=3, show_element_type=True)
show_img.show()
```

The following figure shows the result, with different colored detection boxes representing different categories and displaying specific categories in the upper left corner of the box with `show_element_type`
Expand Down Expand Up @@ -79,6 +81,7 @@ The following model configurations and label maps are currently supported, which
Layout parser contains multiple categories, if you only want to get the detection box for a specific category (such as the "Text" category), you can use the following code:

```python
# follow the above code
# filter areas for a specific text type
text_blocks = lp.Layout([b for b in layout if b.type=='Text'])
figure_blocks = lp.Layout([b for b in layout if b.type=='Figure'])
Expand All @@ -102,9 +105,10 @@ right_blocks.sort(key = lambda b:b.coordinates[1])
text_blocks = lp.Layout([b.set(id = idx) for idx, b in enumerate(left_blocks + right_blocks)])

# display result
lp.draw_box(image, text_blocks,
show_img = lp.draw_box(image, text_blocks,
box_width=3,
show_element_id=True)
show_img.show()
```

Displays results with only the "Text" category:
Expand Down

0 comments on commit bec6ab0

Please sign in to comment.