hiroi-sora / PaddleOCR-json

OCR离线图片文字识别命令行windows程序,以JSON字符串形式输出结果,方便别的程序调用。提供各种语言API。由 PaddleOCR C++ 编译。
Apache License 2.0
826 stars 110 forks source link

编译/打包/发布-相关讨论 #139

Open Gavin1937 opened 6 days ago

Gavin1937 commented 6 days ago

建议以后打包发行时不要用7zip

7zip的压缩包不会保存unix系统的文件权限,这很容易出错。

image

像上面这样,7zip发行压缩包在解压后丢失了PaddleOCR-json可执行程序的执行权限(run.sh的权限还在),这时运行run.sh的话就会报错Permission denied。

这种情况时有时无,不过换成zip就行了。

hiroi-sora commented 6 days ago

了解✓

另外,我觉得v1.4.0差不多可以发正式版了,你还有没有需改动的地方?

https://github.com/hiroi-sora/PaddleOCR-json/blob/927d11e7d297829786fbc3beb3b7a0a294ceb224/cpp/src/main.cpp#L16

过几天Umi也会发个新版本,附带这边的v1.4.0。

Gavin1937 commented 6 days ago

你还有没有需改动的地方

没啥需要加的功能了。

我先更新一个alpha.3版本把发行包换成zip。

话说在发行的时候可以考虑一下github action。用脚本在github action里构建+打包发行,既省事、也能减少人为错误。 Umi-OCR的项目横跨好几个仓库打包起来比较麻烦,不过像这里还有RapidOCR就比较简单了。

hiroi-sora commented 6 days ago

在发行的时候可以考虑一下github action。用脚本在github action里构建+打包发行

好,我之后会学习一下。我先人工构建现版本。

我预计 release/1.4.0 发行包不包含autoclean相关代码,需要的用户自行编译。

autoclean 分支之后改名为 release/1.4.0/autoclean

过段时间跟进 PPOCR v2.7 ,上游已经解决内存泄露的情况下,我们下游不再需要独立的内存清理功能。

Gavin1937 commented 6 days ago

好,我之后会学习一下。我先人工构建现版本。

这个不急,啥时候集成都行。用GitHub action构建和编译很简单,我之前有做过。难的是在打包环节时如何从GitHub action 的环境里找出所有的依赖库。

好在这个项目的大部分依赖库都被包在paddle_inference文件夹里了,只需要找到OpenCV 的依赖就行了。如果直接把OpenCV 安装到GitHub action 的vm系统里,天知道它会把OpenCV 装到什么位置。所以这里主要有两种解决方法:

  1. 自己预先准备一个解压即用的OpenCV(自己编译或者下载发行版后打包),然后放到网上,等GitHub action 要用时再下载就行。因为这是我们自己准备的OpenCV,所以找起里面的文件也很容易。(我之前用的就是这个方案,按我的需求自己编译了个OpenCV 丢在GitHub 上
  2. 按照GitHub 官方推荐的“正确”的方式,先用GitHub action 现场编译一个OpenCV,然后再用GitHub action cache来缓存已编译的依赖,下次就直接从缓存里读取了。

在Windows 下只要有paddle_inference和OpenCV 就可以打包了。

在Linux 下额外需要openmp,不过Linux 版本的GitHub action 可以正常使用docker,直接用docker打包就能完全掌控了。

hiroi-sora commented 6 days ago

linux 构建时有个小问题,直接在这里说了。

按照 Linux 编译指南 完成构建后,可以在本地使用。但是如果要打包为发行版,还需要手动收集 opencv 相关的依赖文件。

我这边通过 apt install libopencv-dev 安装的opencv,或者通过源码编译的,都是大量的零碎小文件。这样不方便收集打包。

image

如何能像你的 release 一样,仅由3个大文件组成opencv依赖包呢?

image

进一步的,可否脚本自动化收集 opencv 相关依赖包,复制到指定目录下?(对于不同平台、不同包管理器,libopencv-dev安装后的文件名可能不同)

Gavin1937 commented 6 days ago

这其实很正常,opencv本身就是一个很大很复杂的库,它自身就有一大堆的依赖。

# 自动寻找系统里的`libpng.so`。
find /usr/lib/ -name libpng.so*

在通过源码编译时,opencv的所有依赖会连带着一起被编译进opencv库里面,所以你所得的共享库都会比用apt install的更大。

(上面是用apt install的opencv,下面是我自己编译的) image

第一种情况:opencv_world是一堆常用的opencv模块集合成的库。像是Windows的opencv发行版用的就是这种形式。

image

第二种情况:那堆opencv_*的共享库就是opencv的不同模块单独拆开的库,也就是你上面图片中那种。

但实际上,这个项目根本用不到全部的opencv模块,它只需要用opencv_coreopencv_imgcodecs,和opencv_imgproc这三个,也就是我在release里面附带的那三个文件。(在CmakeLists里面也只链接了这仨


如何能像你的 release 一样,仅由3个大文件组成opencv依赖包呢?

我的release是和之前提到的我自己编译的opencv链接的,这样就只需要带上那三个opencv模块就行,不用带上其他的opencv依赖库。这里不可以用一个版本的opencv链接,然后再跟另一个版本的opencv一起打包,很容易出错。

可否脚本自动化收集 opencv 相关依赖包,复制到指定目录下?

这个要看平台。在Linux下,可以基于我上面给出的那条命令来写个脚本自动找出所有的opencv库然后复制。不过如果用的是apt install版本的opencv,那就要把它背后的一堆依赖也一起找出来附带上。(我也不知道它有多少依赖,找起来太麻烦了我才去用自己的版本)

如果是Windows,那就完全不知道opencv会被安装在哪了。

我的建议是:直接自己编译两套opencv(Windows和Linux),然后禁用cmake参数BUILD_opencv_world来把所有的模块拆开。这样就可以轻松的找出所有的opencv依赖来发行了。


下面是我自己的opencv的版本信息:

Gavin1937 commented 6 days ago

我更新了一下这个arc-opencv仓库,重新编译了一个禁用opencv_world的Windows opencv,然后更新了一下我用的cmake参数和opencv General Configuration

hiroi-sora commented 5 days ago

OK,感谢。

我使用opencv最新源码和下列指令进行编译:

root_path="./opencv-4.x"
install_path="./opencv-410"
build_dir="./build"

rm -rf ${build_dir}
mkdir ${build_dir}
cd ${build_dir}

cmake "../opencv-4.x" \
    -DCMAKE_INSTALL_PREFIX=${install_path} \
    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_LIST=core,imgcodecs,imgproc \
    -DWITH_IPP=OFF \
    -DBUILD_IPP_IW=OFF \
    -DWITH_LAPACK=OFF \
    -DWITH_EIGEN=OFF \
    -DCMAKE_INSTALL_LIBDIR=lib64 \
    -DWITH_ZLIB=ON \
    -DBUILD_ZLIB=ON \
    -DWITH_JPEG=ON \
    -DBUILD_JPEG=ON \
    -DWITH_PNG=ON \
    -DBUILD_PNG=ON \
    -DWITH_TIFF=ON \
    -DBUILD_TIFF=ON

make -j
make install

得到了体积更小的包:

image

构建 PaddleOCR-json ,打包后的体积也更小。

image

不过,我有点担心在某些平台上,这样是否会缺失依赖项。还需要进一步测试。

另外,你release中 lib/libgomp.so.1 是什么的依赖文件?它是必要的吗?

Gavin1937 commented 5 days ago

不过,我有点担心在某些平台上,这样是否会缺失依赖项。

这个只能多测试了,我是直接开一个docker容器,然后把发行版丢进去看能不能用。

lib/libgomp.so.1 是什么的依赖文件?

这是OpenMP的共享库,在Linux下是必要的,PaddleOCR底层需要它。

至于你使用的cmake参数,

    -DWITH_IPP=OFF \
    -DBUILD_IPP_IW=OFF \
    -DWITH_LAPACK=OFF \
    -DWITH_EIGEN=OFF \

我不建议把这几个给关掉。 IPP能在intel CPU下加速。 然后Lapack和Eigen是两个C++数学运算的库,它们在数学计算上的优化也比opencv自己要好,建议这俩选一个。

hiroi-sora commented 5 days ago

我不建议把这几个给关掉

我简单测试了一下。

上述测试是在 Intel W7-3445 服务器上进行的。跟 Windows i5 13600K 相比,Linux服务器平均慢50%。(两个平台下,PaddleOCR-json 的线程数都设为12)

我想这种性能差距有两种可能:

  1. mkldnn加速在Linux下不生效。
  2. 服务器W7的主频太低(2.60 GHz),比 i5 的 5GHz 低了近一半。

(在服务器下为 PaddleOCR-json 设置更多的线程数,比如20,也是不可行的,处理速度反而会更慢。)

Gavin1937 commented 4 days ago

image

这是我手上编译的几个libopencv_core的对比:

  1. libopencv_core.so.409.RelDebug.new:OpenCV 4.9.0,关掉IPP、Eigen、Lapack,并且以RelWithDebInfo编译

    cmake -S opencv-4.9.0 -B build_opencv_test -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_PERF_TESTS:BOOL=OFF -DBUILD_TESTS:BOOL=OFF \
    -DBUILD_DOCS:BOOL=ON -DWITH_IPP=OFF -DBUILD_IPP_IW=OFF -DWITH_LAPACK=OFF -DWITH_EIGEN=OFF \
    -DBUILD_opencv_world=OFF \
    -DWITH_FFMPEG=ON -DBUILD_JAVA=OFF -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF \
    -DOPENCV_ENABLE_NONFREE=ON -DPARALLEL_ENABLE_PLUGINS=ON \
    -DOPENCV_EXTRA_MODULES_PATH="opencv_contrib-4.9.0/modules" \
    -DBUILD_LIST=core,imgcodecs,imgproc
  2. libopencv_core.so.409.RelDebug.old:OpenCV 4.9.0,以RelWithDebInfo编译 这是从我的arc-opencv仓库里下载的

    cmake -S . -B build -DCMAKE_BUILD_TYPE=RelWithDebInfo -DBUILD_PERF_TESTS:BOOL=OFF \
    -DBUILD_TESTS:BOOL=OFF -DBUILD_DOCS:BOOL=ON -DOPENCV_ENABLE_NONFREE=ON -DPARALLEL_ENABLE_PLUGINS=ON \
    -DOPENCV_EXTRA_MODULES_PATH=/opencv/opencv_contrib-${VERSION}/modules/
  3. libopencv_core.so.409.release:OpenCV 4.9.0,关掉IPP、Eigen、Lapack,并且以Release编译

    cmake -S opencv-4.9.0 -B build_opencv_test -DCMAKE_BUILD_TYPE=Release -DBUILD_PERF_TESTS:BOOL=OFF -DBUILD_TESTS:BOOL=OFF \
    -DBUILD_DOCS:BOOL=ON -DWITH_IPP=OFF -DBUILD_IPP_IW=OFF -DWITH_LAPACK=OFF -DWITH_EIGEN=OFF \
    -DBUILD_opencv_world=OFF \
    -DWITH_FFMPEG=ON -DBUILD_JAVA=OFF -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF \
    -DOPENCV_ENABLE_NONFREE=ON -DPARALLEL_ENABLE_PLUGINS=ON \
    -DOPENCV_EXTRA_MODULES_PATH="opencv_contrib-4.9.0/modules" \
    -DBUILD_LIST=core,imgcodecs,imgproc
  4. libopencv_core.so.410.release:OpenCV 4.10.0,从PaddleOCr-json v1.4.0-beta发行包里拿的

单从包体大小来看,去掉IPP、Lapack、和Eigen确实可以减小体积。 不过这个减少体积的量和控制体积的参数很难琢磨,我自己编译的libopencv_core.so.409.release要比你编译的版本小了10MB。可能是因为我只编译了三个模块?


我想这种性能差距有两种可能

mkldnn在Linux下是有效的,只能是两个CPU之间的差距了。

我个人还是倾向于开启IPP、Lapack、Eigen这几个选项来保证最大程度的优化,毕竟也不知道去掉它们会在不同CPU下对OCR速度有多大的影响,说不定面对一些老CPU或者是很重的OCR场景就不一样了呢?这里没必要为了一点空间而牺牲这些优化选项。如果底层的PaddleOCR有大量用到这些优化相关的功能的话影响就会被放大,反之如果PaddleOCR并不依靠这几个优化参数的话那它们确实不会影响太多。

我觉得这几个优化参数是否开启都没关系,更重要的是要确立一个标准的OpenCV版本,这样子发行打包的时候会方便很多。直接以现在打包进 PaddleOCR-json_v1.4.0.beta_debian_gcc_x86-64.tar.xz 的OpenCV为基准。可以直接编译一套OpenCV丢到GitHub上供大家下载;或者是用docker这样的可控环境;又或者可以去完善脚本来帮开发者一键编译相同配置的OpenCV。

下面是以上的几个libopencv_core的General Configuration

libopencv_core_general_config.zip

下面是一个小脚本,可以从opencv_core里面读取出这些General Configuration(它是直接写入到opencv_core共享库里面的)

#! /usr/bin/env python
from sys import argv

if len(argv) < 2:
        print('Usage: python extract.py /path/to/libopencv_core.so')

start = b'General configuration for OpenCV'
end = b'-----------------------------------------------------------------'

with open(argv[1], 'rb') as file:
        raw = file.read()
        sidx = raw.find(start)
        eidx = raw.find(end, sidx+1) + len(end)
        print(raw[sidx:eidx].decode('utf-8'))
hiroi-sora commented 4 days ago

好建议,收到。

hiroi-sora commented 3 days ago

https://github.com/hiroi-sora/PaddleOCR-json/blob/main/cpp/tools/linux_build_opencv.sh

经过测试,比较完美的cmake参数是:

    -DCMAKE_BUILD_TYPE=Release \
    -DBUILD_LIST=core,imgcodecs,imgproc \
    -DBUILD_SHARED_LIBS=ON \
    -DBUILD_opencv_world=OFF \
    -DOPENCV_FORCE_3RDPARTY_BUILD=ON \
    -DWITH_ZLIB=ON \
    -DWITH_TIFF=ON \
    -DWITH_OPENJPEG=ON \
    -DWITH_JASPER=ON \
    -DWITH_JPEG=ON \
    -DWITH_PNG=ON \
    -DWITH_OPENEXR=ON \
    -DWITH_WEBP=ON \
    -DWITH_IPP=ON \
    -DWITH_LAPACK=ON \
    -DWITH_EIGEN=ON

其中:

opencv-4.10.0-lib.zip

你可以帮我试下,如果没问题的话,就用这组参数和生成的文件作为基准。

Gavin1937 commented 3 days ago

感觉没问题。我测试了一下,把成品的libopencv_core丢进docker debian:stable 容器里与下面这个C++程序链接编译,然后可以正常运行,没有error while loading shared libraries报错。

#include <iostream>
#include <opencv2/opencv.hpp>
int main()
{
  std::cout << cv::getBuildInformation() << std::endl;
  return 0;
}

不过既然是要编译一个发行版的opencv,我觉得可以把opencv的test、doc、java、和python给关掉。

    -DBUILD_PERF_TESTS:BOOL=OFF -DBUILD_TESTS:BOOL=OFF -DBUILD_DOCS:BOOL=OFF \
    -DBUILD_JAVA=OFF -DBUILD_opencv_python2=OFF -DBUILD_opencv_python3=OFF \

下面是我编译出来的共享库大小(用了你的参数+上面这两行) image

还有一个问题是,尽管我已经安装libeigen3-devliblapack-dev,但是我编译出来的版本里面只有Eigen。然后在你的版本里面显示Eigen和Lapack都是禁用的。

下面是我的版本的General Configuration

General configuration for OpenCV 4.10.0 =====================================
  Version control:               unknown

  Platform:
    Timestamp:                   2024-07-07T05:48:15Z
    Host:                        Linux 5.15.0-113-generic x86_64
    CMake:                       3.25.0
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/gmake
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (13 files):         + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (3 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (25 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (2 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                /usr/bin/c++  (ver 11.4.0)
    C++ flags (Release):         -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-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:                 core imgcodecs imgproc
    Disabled:                    python3 world
    Disabled by dependency:      calib3d dnn features2d flann gapi highgui java_bindings_generator js_bindings_generator ml objc_bindings_generator objdetect photo python_bindings_generator python_tests stitching video videoio
    Unavailable:                 java python2 ts
    Applications:                apps
    Documentation:               NO
    Non-free algorithms:         NO

  GUI:
    GTK+:                        NO
    VTK support:                 NO

  Media I/O:
    ZLib:                        build (ver 1.3.1)
    JPEG:                        build-libjpeg-turbo (ver 3.0.3-70)
      SIMD Support Request:      YES
      SIMD Support:              NO
    WEBP:                        build (ver encoder: 0x020f)
    PNG:                         build (ver 1.6.43)
      SIMD Support Request:      YES
      SIMD Support:              YES (Intel SSE)
    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:                      YES (2.2.6)
    FFMPEG:                      YES
      avcodec:                   YES (58.134.100)
      avformat:                  YES (58.76.100)
      avutil:                    YES (56.70.100)
      swscale:                   YES (5.9.100)
      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/user/test3/build_opencv/3rdparty/ippicv/ippicv_lnx/icv
    Intel IPP IW:                sources (2021.11.0)
              at:                /home/user/test3/build_opencv/3rdparty/ippicv/ippicv_lnx/iw
    VA:                          NO
    Lapack:                      NO
    Eigen:                       YES (ver 3.4.0)
    Custom HAL:                  NO
    Protobuf:                    build (3.19.1)
    Flatbuffers:                 builtin/3rdparty (23.5.9)

  OpenCL:                        YES (no extra features)
    Include path:                /home/user/test3/opencv-4.10.0/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

  Python (for build):            /usr/bin/python3

  Install to:                    /usr/local
-----------------------------------------------------------------

下面是你的版本的General Configuration

General configuration for OpenCV 4.10.0 =====================================
  Version control:               f658abd-dirty

  Platform:
    Timestamp:                   2024-07-07T04:59:25Z
    Host:                        Linux 6.5.0-41-generic x86_64
    CMake:                       3.22.1
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/gmake
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3
      requested:                 SSE3
    Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (13 files):         + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (3 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (25 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (2 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

  C/C++:
    Built as dynamic libs?:      YES
    C++ standard:                11
    C++ Compiler:                /usr/bin/c++  (ver 11.4.0)
    C++ flags (Release):         -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fsigned-char -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-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:                 core imgcodecs imgproc
    Disabled:                    world
    Disabled by dependency:      calib3d dnn features2d flann gapi highgui java_bindings_generator js_bindings_generator ml objc_bindings_generator objdetect photo python_bindings_generator python_tests stitching ts video videoio
    Unavailable:                 java python2 python3
    Applications:                apps
    Documentation:               NO
    Non-free algorithms:         NO

  GUI:
    GTK+:                        NO
    VTK support:                 NO

  Media I/O:
    ZLib:                        build (ver 1.3.1)
    JPEG:                        build-libjpeg-turbo (ver 3.0.3-70)
      SIMD Support Request:      YES
      SIMD Support:              NO
    WEBP:                        build (ver encoder: 0x020f)
    PNG:                         build (ver 1.6.43)
      SIMD Support Request:      YES
      SIMD Support:              YES (Intel SSE)
    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:                      YES (2.2.6)
    FFMPEG:                      YES
      avcodec:                   YES (58.134.100)
      avformat:                  YES (58.76.100)
      avutil:                    YES (56.70.100)
      swscale:                   YES (5.9.100)
      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/my/MyCode/PaddleOCR-json/cpp/.source/opencv-4.10.0/build/3rdparty/ippicv/ippicv_lnx/icv
    Intel IPP IW:                sources (2021.11.0)
              at:                /home/my/MyCode/PaddleOCR-json/cpp/.source/opencv-4.10.0/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/my/MyCode/PaddleOCR-json/cpp/.source/opencv-4.10.0/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:                    /home/my/MyCode/PaddleOCR-json/cpp/.source/opencv-release
-----------------------------------------------------------------
yang-521 commented 2 days ago

了解✓

另外,我觉得v1.4.0差不多可以发正式版了,你还有没有需改动的地方?

https://github.com/hiroi-sora/PaddleOCR-json/blob/927d11e7d297829786fbc3beb3b7a0a294ceb224/cpp/src/main.cpp#L16

过几天Umi也会发个新版本,附带这边的v1.4.0。

希望增加方向分类的输出,用于纠正图像的方向

hiroi-sora commented 2 days ago

希望增加方向分类的输出,用于纠正图像的方向

代码改起来不难。

但是,PPOCR的模型中,方向分类cls只是一个 0 或 1 的值。0表示文字是正朝上或顺时针90°,1表示文字是朝下或逆时针90°。对于OCR模型,知道这个值,就足够纠正文字识别了。

但是,用户就没办法知道文字的具体角度,也没办法判断是正朝上还是顺时针旋转了角度。

这样能满足你的需求吗?


要添加的话,只需要在 task.cpp 第91行之前,

https://github.com/hiroi-sora/PaddleOCR-json/blob/26d7c805ad112d1940346618e0731a301820d558/cpp/src/task.cpp#L91

添加以下语句:

            // 写入方向分类相关参数  
            j["cls_label"] = ocr_result[i].cls_label; // 方向标签。0表示0°或顺时针90°,1表示180°或270°,-1表示未启用cls模型  
            j["cls_score"] = ocr_result[i].cls_score; // 方向标签置信度,越接近1越可信。如果未启用cls模型,则始终为0.0    

就可以了。返回json中,每个文本块会多出 cls_label 和 cls_score 两个参数。

yang-521 commented 2 days ago

方向分类cls只是一个 0 或 1 的值。0表示文字是正朝上或顺时针90°,1表示文字是朝下或逆时针90°。

增加这两个就行了,具体怎么解决方向问题我再研究研究

hiroi-sora commented 2 days ago

我调整一下,明天重新打个包

hiroi-sora commented 1 day ago

@yang-521

https://github.com/hiroi-sora/PaddleOCR-json/releases/tag/v1.4.0-beta.2

yang-521 commented 1 day ago

@yang-521

https://github.com/hiroi-sora/PaddleOCR-json/releases/tag/v1.4.0-beta.2

辛苦大佬