Skip to content

Text recognition crnn #176

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
merged 8 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions models/text_recognition_crnn/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
cmake_minimum_required(VERSION 3.24)
set(project_name "opencv_zoo_text_recognition_crnn")

PROJECT (${project_name})

set(OPENCV_VERSION "4.7.0")
set(OPENCV_INSTALLATION_PATH "" CACHE PATH "Where to look for OpenCV installation")
find_package(OpenCV ${OPENCV_VERSION} REQUIRED HINTS ${OPENCV_INSTALLATION_PATH})
# Find OpenCV, you may need to set OpenCV_DIR variable
# to the absolute path to the directory containing OpenCVConfig.cmake file
# via the command line or GUI

file(GLOB SourceFile
"demo.cpp")
# If the package has been found, several variables will
# be set, you can find the full list with descriptions
# in the OpenCVConfig.cmake file.
# Print some message showing some of them
message(STATUS "OpenCV library status:")
message(STATUS " config: ${OpenCV_DIR}")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")

# Declare the executable target built from your sources
add_executable(${project_name} ${SourceFile})

# Link your application with OpenCV libraries
target_link_libraries(${project_name} PRIVATE ${OpenCV_LIBS})
31 changes: 29 additions & 2 deletions models/text_recognition_crnn/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ Note:
- Try `text_recognition_CRNN_CH_2021sep.onnx` with `charset_94_CH.txt`
- Try `text_recognition_CRNN_CN_2021sep.onnx` with `charset_3944_CN.txt`.

### Python

Run the demo detecting English:

```shell
Expand All @@ -52,13 +54,38 @@ Run the demo detecting Chinese:

```shell
# detect on camera input
python demo.py --model text_recognition_CRNN_CN_2021nov.onnx --charset charset_3944_CN.txt
python demo.py --model text_recognition_CRNN_CN_2021nov.onnx
# detect on an image
python demo.py --input /path/to/image --model text_recognition_CRNN_CN_2021nov.onnx --charset charset_3944_CN.txt
python demo.py --input /path/to/image --model text_recognition_CRNN_CN_2021nov.onnx

# get help regarding various parameters
python demo.py --help
```
### C++

Install latest OpenCV and CMake >= 3.24.0 to get started with:

```shell
# detect on camera input
./build/opencv_zoo_text_recognition_crnn
Copy link
Member

Choose a reason for hiding this comment

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

this command can't recognize from camera.

# detect on an image
./build/opencv_zoo_text_recognition_crnn --input /path/to/image -v
Copy link
Member

Choose a reason for hiding this comment

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

need to use -i=/path/to/image or --input=/path/to/image

Copy link
Member

Choose a reason for hiding this comment

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

using -v flag can't show the image

Copy link
Contributor Author

Choose a reason for hiding this comment

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

./build/opencv_zoo_text_recognition_crnn -v=0
show result as text but won't stop without ctrl+c. Must I add a counter to stop after 100 inferences?

Copy link
Member

Choose a reason for hiding this comment

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

I think just be as consistent as possible with other demos

Copy link
Member

Choose a reason for hiding this comment

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

using -v flag can't show the image

Just modify the doc here to make sure the commands work. It does not worth making 100% same behavior as Python demos.


# get help regarding various parameters
./build/opencv_zoo_text_recognition_crnn --help
```

Run the demo detecting Chinese:

```shell
# detect on camera input
./build/opencv_zoo_text_recognition_crnn --model=text_recognition_CRNN_CN_2021nov.onnx --charset=charset_3944_CN.txt
# detect on an image
./build/opencv_zoo_text_recognition_crnn --input=/path/to/image --model=text_recognition_CRNN_CN_2021nov.onnx --charset=charset_3944_CN.txt
Comment on lines +82 to +84
Copy link
Member

Choose a reason for hiding this comment

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

--charset=charset_3944_CN.txt I dont see we have this file in this pull request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

May be there is something I don't understand : in readme

Selected model must match with the charset:

    Try text_recognition_CRNN_EN_2021sep.onnx with charset_36_EN.txt.
    Try text_recognition_CRNN_CH_2021sep.onnx with charset_94_CH.txt
    Try text_recognition_CRNN_CN_2021sep.onnx with charset_3944_CN.txt.

Then i understand that model gives charset to use then in code I use those line

        if (this->modelPath.find("_EN_") != string::npos)
            this->charset = loadCharset("CHARSET_EN_36");
        else if (this->modelPath.find("_CH_") != string::npos)
            this->charset = loadCharset("CHARSET_CH_94");
        else if (this->modelPath.find("_CN_") != string::npos)
            this->charset = loadCharset("CHARSET_CN_3944");
        else
        {
            CV_Error(-1, "Charset not supported! Exiting ...");

        }

Copy link
Member

Choose a reason for hiding this comment

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

We integrated charset characters into the class wrapper crnn.py from separate files, but forgot to update the information in readme. So the current readme is outdated, you might update in this pull request as well.


# get help regarding various parameters
./build/opencv_zoo_text_recognition_crnn --help


### Examples

Expand Down
Loading