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

Add CRAFT character detection node and OCR node. #2650

Merged
merged 27 commits into from Jun 27, 2022

Conversation

iory
Copy link
Member

@iory iory commented Dec 23, 2021

What is this?

Add CRAFT: Character-Region Awareness For Text detection. node which detects text region from image and
add Optical Character Reader (OCR) node from image and text area.

image

This PR is developed on top of this PR.
#2648

Quick Start

Please do rosdep install and catkin build jsk_perception at first.
In order to use this feature, you need to install pytorch <https://pytorch.org/get-started/locally/> (pytorch >= 1.9.0 is recommended).
However, python2 user is not supposed to be able to install that version of torch.
For python2 users, download the appropriate wheel file in your environment from https://download.pytorch.org/whl/cu90/torch_stable.html (melodic) and install with pip as follow:

pip install --user torch-1.1.0-cp27-cp27mu-linux_x86_64.whl
pip install --user torchvision-0.3.0-cp27-cp27mu-manylinux1_x86_64.whl

For python2 users, please do pip install pytesseract==0.3.1 manually because the latest version of pytesseract is not installed automatically.

After that, you can run the following command.

roslaunch jsk_perception sample_craft_node.launch

Japanese OCR recognition

If you want to use a language other than English,
please install the appropriate language data and change the language argument.

For example, if you want to use Japanese,
please install tesseract-ocr-jpn (apt install tesseract-ocr-jpn in Ubuntu) and pass jpn as the language argument.

Copy link
Member

@708yamaguchi 708yamaguchi left a comment

Choose a reason for hiding this comment

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

Sorry, my reviews are WIP.
I will add more reviews later.

craft_node.py
=============

What is this?
Copy link
Member

Choose a reason for hiding this comment

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

How about writing the Quick Start in the comments of this PR in the README as well?

For example, the following information seems very important to me.

For python2 users, please do pip install pytesseract==0.3.1 manually because the latest version of pytesseract is not installed automatically.

In addition, I was confused when installing pytorch with python2.
The followint web page show only for python3 user.
https://pytorch.org/get-started/locally/
Could you please add pytorch installation process for python 2 users?

Copy link
Member

Choose a reason for hiding this comment

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

Related to the these python version problem, how about using catkin_virtualenv to use the latest pip programs with Python3.x.
I think this makes the installation process easier.

Copy link
Member Author

@iory iory Dec 24, 2021

Choose a reason for hiding this comment

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

Related to the these python version problem, how about using catkin_virtualenv to use the latest pip programs with Python3.x. I think this makes the installation process easier.

I'm not familiar with catkin_virtualenv. I have a question.
catkin_install_python needs to call catkin_install_python, but the script files are already written as a target in CMakelists.txt in jsk_perception. https://github.com/jsk-ros-pkg/jsk_recognition/blob/master/jsk_perception/CMakeLists.txt#L430-L435
Does this mean that the script files also need to be changed to work with python3?
If that is true, I think we need to address it with another PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

How about writing the Quick Start in the comments of this PR in the README as well?

Could you please add pytorch installation process for python 2 users?

Thanks. I added them.
4a49d1d
a51b8ca

Copy link
Member

Choose a reason for hiding this comment

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

I'm not familiar with catkin_virtualenv. I have a question.
catkin_install_python needs to call catkin_install_python, but the script files are already written as a target in CMakelists.txt in jsk_perception. master/jsk_perception/CMakeLists.txt#L430-L435
Does this mean that the script files also need to be changed to work with python3?

I am very sorry, but you are right. We should not use catkin_virtualenv.

This process will also override the standard catkin_install_python macro to wrap a virtualenv loader around the specified python scripts.
https://github.com/locusrobotics/catkin_virtualenv

In addition to that, using catkin_virtualenv adds new dependency to jsk_perception. So we should not use catkin_virtualenv

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. I understand it.

@708yamaguchi
Copy link
Member

Thank you very much for your help.
I was able to successfully run the sample!
This PR seems very useful.

Is it difficult to add a test to this?
In my understanding, what we need to do is

  • Add .test file using sample_craft_node.launch (gpu:=-1 is needed?)
  • Update CMakeLists.txt
  • Update BEFORE_SCRIPT in .github/workflow


.. code-block:: bash

pip install --user torch-1.1.0-cp27-cp27mu-linux_x86_64.whl
Copy link
Member

Choose a reason for hiding this comment

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

I have a question.

You say (pytorch >= 1.4.0 is recommended), but the installed torch version seems 1.1.0

Does this mean "Python3 users should use torch>=1.4.0, but Python2 users should use torch=1.1.0" ?

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. I modified the description.
a4beeae
Please check it

Copy link
Member

Choose a reason for hiding this comment

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

Thank you!
Very easy to understand.

@708yamaguchi
Copy link
Member

When no character is found, I got the error.

Could you check this PR?
iory#14

@iory
Copy link
Member Author

iory commented Dec 24, 2021

When no character is found, I got the error. Could you check this PR?

Merged. Thanks!

@708yamaguchi
Copy link
Member

708yamaguchi commented Dec 24, 2021

I think this PR works well. After tests pass, it will be OK to merge.
Great work!

I have a simple question. (Maybe future work)

When the characters are parallel to the image, the recognition accuracy is high.

Screenshot 2021-12-24 23:50:15

However, when it is not, the recognition accuracy seems to be low.

Screenshot 2021-12-24 23:51:04

How can we avoid this?
Parameter tunings?
Or if we can know the rotation angle of the strings, we can rotate the image?

@tkmtnt7000
Copy link
Member

Sorry to interrupt.
I think it is a nice and useful PR. Overall, the ability to recognize Japanese words is also reasonably high!

OCR Rect
(Image source: Amazon.com)

Comment on lines 50 to 52
* ``~gpu`` (Int, default: ``0``)

GPU id.
Copy link
Member

Choose a reason for hiding this comment

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

If a version that runs on the CPU is supported, it might be easier for users to understand when the value to set in the case of the CPU is written like https://github.com/jsk-ros-pkg/jsk_recognition/blame/master/doc/jsk_perception/nodes/hand_pose_estimation_2d.rst#L39-L41

Copy link
Member Author

Choose a reason for hiding this comment

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

85a4d68
Thanks. I added the information.

Copy link
Member

Choose a reason for hiding this comment

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

Thank you!

@708yamaguchi
Copy link
Member

708yamaguchi commented Dec 24, 2021

kinetic, melodic, noetic and noetic-full tests do not start.

For example,

Invalid workflow file : .github/workflows/noetic.yml#L35
The workflow is not valid. .github/workflows/noetic.yml (Line: 35, Col: 13): A sequence was not expected

https://github.com/jsk-ros-pkg/jsk_recognition/actions/runs/1619482923

This may be solved with:

SamKirkland/FTP-Deploy-Action#202 (comment)
SamKirkland/FTP-Deploy-Action#202 (comment)
SamKirkland/FTP-Deploy-Action#202 (comment)

@iory
Copy link
Member Author

iory commented Dec 24, 2021

How can we avoid this?
Parameter tunings?
Or if we can know the rotation angle of the strings, we can rotate the image?

I modified the crop code.
2f70e56
However, this is not perfect.
Depending on the position of the four points of the input polygon, the image to be cropped may be distorted.
The solution to this is to crop the text so that it is no longer distorted, or to improve the performance of OCR.
These solutions are future direction.

@708yamaguchi
Copy link
Member

The recognition accuracy seems to have improved when the characters are rotated.
Thank you!

Screenshot 2021-12-25 10:26:50

@708yamaguchi
Copy link
Member

melodic test fails because pytesseract installation fails

2021-12-24T20:41:06.0722380Z   pip: command [sudo -H pip2 install -U -q pytesseract] failed
2021-12-24T20:41:06.0723230Z   pip: Failed to detect successful installation of [pytesseract]
2021-12-24T20:41:06.9390096Z Traceback (most recent call last):
2021-12-24T20:41:06.9390434Z 
2021-12-24T20:41:06.9390786Z                                                                                 
2021-12-24T20:41:06.9391609Z   File "/workspace/ros/ws_jsk_recognition/src/jsk_recognition/jsk_perception/node_scripts/ocr_node.py", line 25, in <module>
2021-12-24T20:41:06.9392271Z 
2021-12-24T20:41:06.9392625Z                                                                                 
2021-12-24T20:41:06.9393080Z     import pytesseract
2021-12-24T20:41:06.9393385Z 
2021-12-24T20:41:06.9393732Z                                                                                 
2021-12-24T20:41:06.9394356Z ImportError: No module named pytesseract

https://github.com/jsk-ros-pkg/jsk_recognition/runs/4628721970?check_suite_focus=true

We may need to add

pip install pytesseract==0.3.1

to BEFORE_SCRIPT

@708yamaguchi
Copy link
Member

kinetic, noetic and noetic-full tests fail maybe because format of BEFORE_SCRIPT is not correct (as iory checked with ce1bf09)

@iory iory force-pushed the craft-ocr branch 3 times, most recently from 5f1d22e to 13c8ba2 Compare December 26, 2021 14:44
@mqcmd196
Copy link
Member

mqcmd196 commented Dec 27, 2021

LGTM, I could execute the node successfully.

@k-okada
Copy link
Member

k-okada commented Dec 30, 2021

@iory
Copy link
Member Author

iory commented Jun 22, 2022

I resolved conflicts. I'm waiting for test results.

@iory iory force-pushed the craft-ocr branch 7 times, most recently from 185e519 to 11cbc31 Compare June 23, 2022 19:54
@iory
Copy link
Member Author

iory commented Jun 26, 2022

@k-okada
I modified the GA config to install pytorch. 0224bd0
Test passed.

@k-okada
Copy link
Member

k-okada commented Jun 27, 2022

@k-okada k-okada merged commit 39e37cb into jsk-ros-pkg:master Jun 27, 2022
@iory iory deleted the craft-ocr branch June 27, 2022 04:54
@@ -92,6 +92,7 @@
<exec_depend>leveldb</exec_depend>
<exec_depend>python-fcn-pip</exec_depend> <!-- pip -->
<!-- }} install fcn -->
<exec_depend version_lt="0.3.7">python-pytesseract-pip</exec_depend>
Copy link
Contributor

@pazeshun pazeshun Jun 27, 2022

Choose a reason for hiding this comment

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

@iory Isn't this 0.3.6? 0.3.7 causes syntax error.
Sorry, my mistake.
I overlooked version_lt, means "less than"

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. Thanks.

@iory
Copy link
Member Author

iory commented Jun 27, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants