当前位置:   article > 正文

ChineseOcr Lite Ncnn:高效轻量级中文OCR工具_ocrlitencnn

ocrlitencnn

在这里插入图片描述

前言

ChineseOcr Lite Ncnn,超轻量级中文OCR PC Demo,支持ncnn推理;

opencv编译

编译命令

# 源码下载
git clone https://github.com/opencv/opencv.git
cd opencv
mkdir build && cd build
cmake ..
make -j4
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

编译结果

root@kaixuan-PC:/home/kaixuan/Desktop/ocr/ncnn# git clone https://github.com/opencv/opencv.git
正克隆到 'opencv'...
remote: Enumerating objects: 331436, done.
remote: Counting objects: 100% (230/230), done.
remote: Compressing objects: 100% (156/156), done.
remote: Total 331436 (delta 103), reused 153 (delta 69), pack-reused 331206
接收对象中: 100% (331436/331436), 521.32 MiB | 2.14 MiB/s, 完成.
处理 delta 中: 100% (231146/231146), 完成.
正在检出文件: 100% (7452/7452), 完成.
root@kaixuan-PC:/home/kaixuan/Desktop/ocr/ncnn# ls
opencv
root@kaixuan-PC:/home/kaixuan/Desktop/ocr/ncnn# cd opencv/
root@kaixuan-PC:/home/kaixuan/Desktop/ocr/ncnn/opencv# ls
3rdparty  apps	cmake  CMakeLists.txt  CONTRIBUTING.md	COPYRIGHT  data  doc  include  LICENSE	modules  platforms  README.md  samples	SECURITY.md
root@kaixuan-PC:/home/kaixuan/Desktop/ocr/ncnn/opencv# mkdir build && cd build
root@kaixuan-PC:/home/kaixuan/Desktop/ocr/ncnn/opencv/build# cmake ..
-- 'Release' build type is used by default. Use CMAKE_BUILD_TYPE to specify build type (Release or Debug)
-- The CXX compiler identification is GNU 8.3.0
-- The C compiler identification is GNU 8.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
...
...
...
long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined  
--     Linker flags (Debug):        -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined  
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          dl m pthread rt
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 calib3d core dnn features2d flann gapi highgui imgcodecs imgproc ml objdetect photo stitching ts video videoio
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 java python2 python3
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
-- 
--   GUI:                           NONE
--     GTK+:                        NO
--     VTK support:                 NO
-- 
--   Media I/O: 
--     ZLib:                        zlib (ver 1.3.1)
--     JPEG:                        build-libjpeg-turbo (ver 2.1.3-62)
--       SIMD Support Request:      YES
--       SIMD Support:              NO
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         build (ver 1.6.37)
--     TIFF:                        build (ver 42 - 4.6.0)
--     JPEG 2000:                   build (ver 2.5.0)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
-- 
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      NO
--       avcodec:                   NO
--       avformat:                  NO
--       avutil:                    NO
--       swscale:                   NO
--       avresample:                NO
--     GStreamer:                   NO
--     v4l/v4l2:                    YES (linux/videodev2.h)
-- 
--   Parallel framework:            pthreads
-- 
--   Trace:                         YES (with Intel ITT)
-- 
--   Other third-party libraries:
--     Intel IPP:                   2021.11.0 [2021.11.0]
--            at:                   /home/kaixuan/Desktop/ocr/ncnn/opencv/build/3rdparty/ippicv/ippicv_lnx/icv
--     Intel IPP IW:                sources (2021.11.0)
--               at:                /home/kaixuan/Desktop/ocr/ncnn/opencv/build/3rdparty/ippicv/ippicv_lnx/iw
--     VA:                          NO
--     Lapack:                      NO
--     Eigen:                       NO
--     Custom HAL:                  NO
--     Protobuf:                    build (3.19.1)
--     Flatbuffers:                 builtin/3rdparty (23.5.9)
-- 
--   OpenCL:                        YES (no extra features)
--     Include path:                /home/kaixuan/Desktop/ocr/ncnn/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
-- 
--   Python (for build):            /usr/bin/python3
-- 
--   Java:                          
--     ant:                         NO
--     Java:                        NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
-- 
--   Install to:                    /usr/local
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kaixuan/Desktop/ocr/ncnn/opencv/build
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107

ncnn设置

不同版本ncnn源码下载,ncnn文件存放路径;

OcrLiteNcnn/ncnn-static
├── NcnnWrapperConfig.cmake
├── linux
├── macos
├── windows-x64
└── windows-x86

OcrLiteNcnn编译

OcrLiteNcnn1.8.0源码下载

  1. 小编调整后的源码(百度云盘),提取码:5566下载,ncnn文件已配置好,可直接使用;
  2. OcrLiteNcnn不同版本源码下载;将ncnn文件存放到指定目录(参照"ncnn设置");
  1. Source code (tar.gz):linux源码;
  2. Source code (zip):windows源码;
  3. *.7z:编译好的不同平台可执行程序,没有特殊要求可直接使用;

OcrLiteNcnn1.8.0源码编译

root@kaixuan-PC:/home/kaixuan/Desktop/ocr# cd OcrLiteNcnn-1.8.0/
root@kaixuan-PC:/home/kaixuan/Desktop/ocr/OcrLiteNcnn-1.8.0# ./build.sh 
========请先参考README.md准备好编译环境========

========编译选项========
请输入编译选项并回车: 1)Release, 2)Debug
1
请选择要使用的ncnn库选项并回车: 1)ncnn(CPU),2)ncnn(vulkan)
1
请注意:如果选择2)JNI动态库时,必须安装配置Oracle JDK
请选择编译输出类型并回车: 1)BIN可执行文件,2)JNI动态库,3)C动态库
1
/home/kaixuan/Desktop/ocr/OcrLiteNcnn-1.8.0/Linux-BIN-CPU /home/kaixuan/Desktop/ocr/OcrLiteNcnn-1.8.0
cmake -DCMAKE_INSTALL_PREFIX=install -DCMAKE_BUILD_TYPE=Release -DOCR_OUTPUT=BIN -DOCR_VULKAN=CPU ..
-- The C compiler identification is GNU 8.3.0
-- The CXX compiler identification is GNU 8.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
配置Linux ncnn 路径: /home/kaixuan/Desktop/ocr/OcrLiteNcnn-1.8.0/ncnn-static/linux/lib/cmake/ncnn
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Check if compiler accepts -pthread
-- Check if compiler accepts -pthread - yes
-- Found Threads: TRUE  
-- ncnn Found!
配置Linux OpenCV 路径: /home/kaixuan/Desktop/ocr/OcrLiteNcnn-1.8.0/opencv-static/linux/lib/cmake/opencv4
-- Found OpenCV: /usr/local (found version "4.9.0") 
-- OpenCV_LIBS: opencv_calib3d;opencv_core;opencv_dnn;opencv_features2d;opencv_flann;opencv_gapi;opencv_highgui;opencv_imgcodecs;opencv_imgproc;opencv_ml;opencv_objdetect;opencv_photo;opencv_stitching;opencv_video;opencv_videoio
-- OpenCV_INCLUDE_DIRS: /usr/local/include/opencv4
-- Configuring done
-- Generating done
-- Build files have been written to: /home/kaixuan/Desktop/ocr/OcrLiteNcnn-1.8.0/Linux-BIN-CPU
Scanning dependencies of target benchmark
Scanning dependencies of target OcrLiteNcnn
[  9%] Building CXX object CMakeFiles/benchmark.dir/benchmark/benchmark.cpp.o
...
...
...
[100%] Built target OcrLiteNcnn
Install the project...
-- Install configuration: "Release"
-- Installing: /home/kaixuan/Desktop/ocr/OcrLiteNcnn-1.8.0/Linux-BIN-CPU/install/bin/OcrLiteNcnn
-- Set runtime path of "/home/kaixuan/Desktop/ocr/OcrLiteNcnn-1.8.0/Linux-BIN-CPU/install/bin/OcrLiteNcnn" to ""
-- Installing: /home/kaixuan/Desktop/ocr/OcrLiteNcnn-1.8.0/Linux-BIN-CPU/install/bin/benchmark
-- Set runtime path of "/home/kaixuan/Desktop/ocr/OcrLiteNcnn-1.8.0/Linux-BIN-CPU/install/bin/benchmark" to ""
/home/kaixuan/Desktop/ocr/OcrLiteNcnn-1.8.0
kaixuan@kaixuan-PC:~/Desktop/ocr/OcrLiteNcnn-1.8.0$ cd Linux-BIN-CPU/
kaixuan@kaixuan-PC:~/Desktop/ocr/OcrLiteNcnn-1.8.0/Linux-BIN-CPU$ ls
benchmark  CMakeCache.txt  CMakeFiles  cmake_install.cmake  install  install_manifest.txt  Makefile  OcrLiteNcnn
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59

OCR图片文本识别测试

编译文件测试命令

./OcrLiteNcnn 
-d /home/kaixuan/Desktop/ocr/models-1.8 
-i /home/kaixuan/Desktop/ocr/1111.jpeg 
-f /home/kaixuan/Desktop/ocr/1212.txt
  • 1
  • 2
  • 3
  • 4

OcrLiteNcnn:编译结果文件
-d:模型文件所在目录
-i:需要识别的图片
-f:识别结果输出文件

编译文件测试输出

kaixuan@kaixuan-PC:~/Desktop/ocr/OcrLiteNcnn-1.8.0$ cd Linux-BIN-CPU/
kaixuan@kaixuan-PC:~/Desktop/ocr/OcrLiteNcnn-1.8.0/Linux-BIN-CPU$ ./OcrLiteNcnn -d /home/kaixuan/Desktop/ocr/models-1.8 -i /home/kaixuan/Desktop/ocr/1111.jpeg -f /home/kaixuan/Desktop/ocr/1212.txt
秘密10年
东海市文件
签发:
东文[2019129号
关于检测文件是否为模板的测试
第一条为了保护民事主体的合法权益,调整民事关
系,维护社会和经济秩序,适应中国特色社会主义发展要求,
弘扬社会主义核心价值观,根据宪法,制定本法。
第二条民法调整平等主体的自然人、法人和非法人组
织之间的人身关系和财产关系。
第三条 民事主体的人身权利、财产权利以及其他合法
权益受法律保护,任何组织或者个人不得侵犯。
第四条民事主体在民事活动中的法律地位一律平等。
第五条民事主体从事民事活动,应当遵循自愿原则
按照自己的意思设立、变更、终止民事法律关系
第六条 民事主体从事民事活动,应当遵循公平原则
合理确定各方的权利和义务。
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

模型下载

小编使用识别模型(OcrLiteNcnn-models-1.8.rar)

相关链接

  1. https://github.com/benjaminwan/OcrLiteNcnn
  2. https://github.com/benjaminwan/OcrLiteNcnn/releases
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/煮酒与君饮/article/detail/771318
推荐阅读
相关标签
  

闽ICP备14008679号