diff --git a/doc/table/layout.png b/doc/table/layout.png new file mode 100644 index 0000000000000000000000000000000000000000..d8b56701f611593b2188c8d4844966ab48a8fb91 Binary files /dev/null and b/doc/table/layout.png differ diff --git a/ppstructure/layout/README.md b/ppstructure/layout/README.md index 9f53500324cc7c0756a5475b646a606ed86c0f82..a193ffd3b979535bed003dc884c2c34adf24b701 100644 --- a/ppstructure/layout/README.md +++ b/ppstructure/layout/README.md @@ -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] # 加载模型 @@ -39,7 +39,8 @@ model = lp.PaddleDetectionLayoutModel(config_path="lp://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`在框的左上角显示具体类别: @@ -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']) @@ -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"类别的结果: diff --git a/ppstructure/layout/README_en.md b/ppstructure/layout/README_en.md index d31dbe35a4ea7d12ab127f20be7748c8fa85deff..d94b2aa47ef10724d23ce0ff813dffdd7dde6eb7 100644 --- a/ppstructure/layout/README_en.md +++ b/ppstructure/layout/README_en.md @@ -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 @@ -39,7 +40,8 @@ model = lp.PaddleDetectionLayoutModel(config_path="lp://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` @@ -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']) @@ -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: