Skip to content
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

【PaddlePaddle Hackathon 4】No.205 add a meter reader notebook #1030

Open
wants to merge 61 commits into
base: main
Choose a base branch
from

Conversation

Liyulingyue
Copy link

According to #998, I add a notebook about meter reader. The meter reader recognizes text based on the given layout information and outputs it in a structured format.

Summary

  • Reuse some code in 405-paddle-ocr-webcam. Encapsulate the code of 405 and provide an API for OCR that can be called with one click.
  • Established a complete structured output process.

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

Copy link
Collaborator

@OpenVINO-dev-contest OpenVINO-dev-contest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Liyulingyue thanks for your contribution, and I have put some rough comments on this PR. Could you take a look and fix the code format issue on CI ?

notebooks/203-meter-reader/processing.py Outdated Show resolved Hide resolved
notebooks/203-meter-reader/processing.py Outdated Show resolved Hide resolved
notebooks/203-meter-reader/WorkFlow_with_ppocr.png Outdated Show resolved Hide resolved
@Liyulingyue
Copy link
Author

This comment is only used to upload two imgs

Example jpg
WorkFlow_with_ppocr

@Liyulingyue
Copy link
Author

This comment is only used to upload example imgs
MicrosoftTeams-image

@Liyulingyue
Copy link
Author

This comment is only used to upload framework imgs
图片1

Copy link
Collaborator

@OpenVINO-dev-contest OpenVINO-dev-contest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Please use "crop" instead of "cut" in this notebook.
  2. Shall we use "Segment code LCD" or "segment code LCD"?

"# Digital Meter Reader \n",
"This notebook shows how to create a meter reader with OpenVINO Runtime. We use the pre-trained [PP-OCR](https://github.com/PaddlePaddle/PaddleOCR) to build up a inference task pipeline:\n",
"\n",
"1. Configure the screen area of the meter reader.\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use same words in workflow diagram, or add these numbers in diagram which will make the pipeline more clear.

notebooks/203-meter-reader/203-meter-reader-digital.ipynb Outdated Show resolved Hide resolved
notebooks/203-meter-reader/203-meter-reader-digital.ipynb Outdated Show resolved Hide resolved
notebooks/203-meter-reader/203-meter-reader-digital.ipynb Outdated Show resolved Hide resolved
notebooks/203-meter-reader/203-meter-reader-digital.ipynb Outdated Show resolved Hide resolved
"outputs": [],
"source": [
"# the input of recognition should be image, DESIGN information, compiled_model\n",
"def main_for_field_strength_meter(img, DESIGN_LAYOUT, RESULT_TEMP, rec_compiled_model, rec_output_layer, text_decoder):\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since most of codes of 2 main function can be reusable except some special condition, I will highly recommend you to combine them into one, and put it in section 2.

Liyulingyue and others added 4 commits May 24, 2023 12:24
Co-authored-by: Ethan Yang <ethan.yang@intel.com>
Co-authored-by: Ethan Yang <ethan.yang@intel.com>
Co-authored-by: Ethan Yang <ethan.yang@intel.com>
Co-authored-by: Ethan Yang <ethan.yang@intel.com>
@Liyulingyue
Copy link
Author

图片2

Copy link
Collaborator

@OpenVINO-dev-contest OpenVINO-dev-contest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @Liyulingyue Please also help to update the README file.

notebooks/203-meter-reader/203-meter-reader-digital.ipynb Outdated Show resolved Hide resolved
Copy link
Collaborator

@OpenVINO-dev-contest OpenVINO-dev-contest left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hi @Liyulingyue Please also help to update the README file, and fix the code format issue on CI

@@ -0,0 +1,1059 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested changes:

This notebook shows how to create a meter reader with OpenVINO Runtime for industrial digital meters. We use the pre-trained PP-OCR to recognize the required text and numbers on industrial digital meters, with the following inference task pipeline:

  1. Configure the screen area of the digital meter reader.
  2. Preprocess the input image (affine transformations)
  3. Configure the layout information of the digital meter reader, and crop the input image into small pieces with areas required to be recognized.
  4. (Optional) Preprocess the cropped images for meters with LCD screen.
  5. Perform OCR recognition with OpenVINO.
  6. Structure output information.
  7. (Optional) Postprocess the output information when necessary.

This notebook will demonstrate how to read digital meters with different types of screens. In case 1 there is a field strength meter with general screen, which means that we can read the pure text directly from the screen with OCR. In case 2, there is a household electricity meter with Segment code LCD screen, which means we can not only see the required text, but also the outline of the redundant text in the background. The background outline could also be misread by the model as the content that needs to be recognized, so we need to add some preprocessing module to remove the redundant background information.

Most of the process for the two types of digital meters is similar, we only make some modifications in the preprocessing for the two different meters. The following figure shows the flowchart of two types of meter readers.

The tutorial consists of the following steps:

  1. Prepare the PaddleOCR model.
  2. Define configuration and helper functions
  • Prepare configuration (take general screen meters as an example)
  • Define a helper function to apply affine transformation
  • Define helper functions for the preprocessing of text recognition
  • Define helper functions for the postprocessing of text recognition
  1. Meter reading for general screen digital meters
  • Download Image
  • Apply the affine transformation
  • Define the areas to be recognized
  • Recognize the text with OpenVINO on preprocessed images
  • Postprocessing to fix the errors in recognition
  1. Meter reading for Segment code LCD screen digital meters
  • Prepare the Image, and apply configurations and special preprocessing for Segment code LCD screen
  • Recognize the text with OpenVINO on preprocessed images (containing affine transformation)
  • Postprocessing to fix the errors in recognition


Reply via ReviewNB

@@ -0,0 +1,1059 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested changes:
note: The concepts of 'DESIGN_SHAPE' and 'DESIGN_LAYOUT' refer to the fact that the layout information of a display screen is determined during design, and these information is independent of the image. Therefore, you can obtain 'DESIGN_LAYOUT' information from your device manual. However, a simple way to run the program is to treat the coordinates of some points in figure as 'DESIGN_LAYOUT'. You can use Paint, a windows application, to obtain the coordinates. You only need to move the mouse to a position on the image, and the tool will display the corresponding coordinates.

Can you provide a link to the "Paint" here, so that other developers could directly link to this app and obtain the DESIGN_LAYOUT information?

For "DESIGN_LAYOUT", when you mention "the layout information of a display screen is determined during design, and these information is independent of the image", so it means the area of the LCD screen on the digital meter (the coordinates of the four vertices of the rectangle area), right?


Reply via ReviewNB

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for replying late.

For "DESIGN_LAYOUT", when you mention "the layout information of a display screen is determined during design, and these information is independent of the image", so it means the area of the LCD screen on the digital meter (the coordinates of the four vertices of the rectangle area), right?

about the above question, the answer is right.

@Liyulingyue
Copy link
Author

update two source img
MicrosoftTeams-image (1)
图片1

notebooks/203-meter-reader/README.md Outdated Show resolved Hide resolved
notebooks/203-meter-reader/README.md Outdated Show resolved Hide resolved
@@ -2,16 +2,32 @@

[![Binder](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/openvinotoolkit/openvino_notebooks/HEAD?labpath=notebooks%2F203-meter-reader%2F203-meter-reader.ipynb)

![meter](https://user-images.githubusercontent.com/91237924/166135627-194405b0-6c25-4fd8-9ad1-83fb3a00a081.jpg)
<html>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you help to fix the layout of these pictures, it looks twisted.
image

Co-authored-by: Ethan Yang <ethan.yang@intel.com>
@Liyulingyue
Copy link
Author

update image
图片1

Liyulingyue and others added 2 commits May 29, 2023 18:38
@@ -0,0 +1,1055 @@
{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line #96.    text_decoder = RecLabelDecode(character_dict_path="../data/text/ppocr_keys_v1.txt",

Missing file: ppocr_keys_v1.txt


Reply via ReviewNB

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The most thing about paddleocr will be very similar to https://github.com/openvinotoolkit/openvino_notebooks/blob/2023.2/notebooks/405-paddle-ocr-webcam/405-paddle-ocr-webcam.ipynb, and the ppocr_keys_v1.txt file can be found in the ipynb.

The most related codes are:

# Download font and a character dictionary for printing OCR results.
font_path = utils.download_file(
    url='https://raw.githubusercontent.com/Halfish/lstm-ctc-ocr/master/fonts/simfang.ttf',
    directory='fonts'
)
character_dictionary_path = utils.download_file(
    url='https://raw.githubusercontent.com/WenmuZhou/PytorchOCR/master/torchocr/datasets/alphabets/ppocr_keys_v1.txt',
    directory='fonts'
)

And you can download the file from that url :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
paddle hackathon PaddlePaddle Hackathon 4 contribution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants