Skip to content

Support rectangle in draw_boxes and relocate draw_ser_results #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

hongziqi
Copy link
Contributor

@hongziqi hongziqi commented Oct 28, 2024

Thank you for your contribution to the MindOCR repo.
Before submitting this PR, please make sure:

Motivation

  1. Update mindocr.utils.visualize.draw_boxes function to support rectangle draw_type:
    The current draw_boxes function only supports drawing polygons. Adding support for drawing rectangles will enhance its versatility and make it more useful for various applications that require drawing bounding boxes in both polygon and rectangle formats.

  2. Move tools.infer.text.predict_ser.draw_ser_results to mindocr.utils.visualize:
    The draw_ser_results function is currently located in tools.infer.text.predict_ser, which may not be the most intuitive location for a utility function that deals with visualizing OCR results. Moving it to mindocr.utils.visualize will improve the organization of the codebase, making it easier for developers to find and use this function.

Test Plan

  • draw_boxes is only used by tools/infer/text/predict_det.py
  • draw_ser_results is only used by tools/infer/text/predict_ser.py
  1. before change:
    case one (python tools/infer/text/predict_det.py --image_dir configs/kie/vi_layoutxlm/example.jpg --det_algorithm DB++):
    image

case two(python tools/infer/text/predict_ser.py --det_algorithm DB++ --rec_algorithm CRNN_CH --image_dir configs/kie/vi_layoutxlm/example.jpg)
image

  1. after change:
    case one (python tools/infer/text/predict_det.py --image_dir configs/kie/vi_layoutxlm/example.jpg --det_algorithm DB++):
    image

case two(python tools/infer/text/predict_ser.py --det_algorithm DB++ --rec_algorithm CRNN_CH --image_dir configs/kie/vi_layoutxlm/example.jpg)
image

case three(test for draw_boxes with rectangle draw_type):

def test_draw_boxes_rectangle():
    # 创建一个空白图像
    image = np.zeros((400, 400, 3), dtype=np.uint8)

    # 定义矩形框的坐标
    bboxes = np.array([
        [50, 50, 150, 150],
        [200, 200, 300, 300]
    ])

    # from mindocr.utils.visualize import draw_boxes, show_imgs
    result_image = draw_boxes(image, bboxes, draw_type="rectangle")
    show_imgs([result_image], show=False, save_path="./inference_results/test_rectangle_output.jpg")
test_draw_boxes_rectangle()

image

@hongziqi hongziqi force-pushed the feat-update-mindocr-visualize branch from 8f34a80 to 70c4907 Compare October 28, 2024 03:55
2.mv tools.infer.text.predict_ser.draw_ser_results to mindocr.utils.visualize
@hongziqi hongziqi force-pushed the feat-update-mindocr-visualize branch from 70c4907 to 68db6bb Compare October 28, 2024 04:00
@kk928290341 kk928290341 merged commit d20a39e into mindspore-lab:main Oct 29, 2024
2 checks passed
@hongziqi hongziqi deleted the feat-update-mindocr-visualize branch October 30, 2024 10:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants