Open Gavin1937 opened 6 days ago
了解✓
另外,我觉得v1.4.0差不多可以发正式版了,你还有没有需改动的地方?
过几天Umi也会发个新版本,附带这边的v1.4.0。
你还有没有需改动的地方
没啥需要加的功能了。
我先更新一个alpha.3版本把发行包换成zip。
话说在发行的时候可以考虑一下github action。用脚本在github action里构建+打包发行,既省事、也能减少人为错误。 Umi-OCR的项目横跨好几个仓库打包起来比较麻烦,不过像这里还有RapidOCR就比较简单了。
在发行的时候可以考虑一下github action。用脚本在github action里构建+打包发行
好,我之后会学习一下。我先人工构建现版本。
我预计 release/1.4.0
发行包不包含autoclean相关代码,需要的用户自行编译。
autoclean
分支之后改名为 release/1.4.0/autoclean
。
过段时间跟进 PPOCR v2.7 ,上游已经解决内存泄露的情况下,我们下游不再需要独立的内存清理功能。
好,我之后会学习一下。我先人工构建现版本。
这个不急,啥时候集成都行。用GitHub action构建和编译很简单,我之前有做过。难的是在打包环节时如何从GitHub action 的环境里找出所有的依赖库。
好在这个项目的大部分依赖库都被包在paddle_inference文件夹里了,只需要找到OpenCV 的依赖就行了。如果直接把OpenCV 安装到GitHub action 的vm系统里,天知道它会把OpenCV 装到什么位置。所以这里主要有两种解决方法:
在Windows 下只要有paddle_inference和OpenCV 就可以打包了。
在Linux 下额外需要openmp,不过Linux 版本的GitHub action 可以正常使用docker,直接用docker打包就能完全掌控了。
linux 构建时有个小问题,直接在这里说了。
按照 Linux 编译指南 完成构建后,可以在本地使用。但是如果要打包为发行版,还需要手动收集 opencv 相关的依赖文件。
我这边通过 apt install libopencv-dev
安装的opencv,或者通过源码编译的,都是大量的零碎小文件。这样不方便收集打包。
如何能像你的 release 一样,仅由3个大文件组成opencv依赖包呢?
进一步的,可否脚本自动化收集 opencv 相关依赖包,复制到指定目录下?(对于不同平台、不同包管理器,libopencv-dev
安装后的文件名可能不同)
这其实很正常,opencv本身就是一个很大很复杂的库,它自身就有一大堆的依赖。
apt install libopencv-dev
安装opencv时,很多系统的包管理器会把opencv的依赖给单独安装(至少debian系的是这样的)。你可以去/usr/lib
目录下找找,应该能看到一堆opencv的依赖库。像是libpng.so
, libjpeg.so
, libwebp.so
这些。# 自动寻找系统里的`libpng.so`。
find /usr/lib/ -name libpng.so*
opencv_world
和opencv_videoio_ffmpeg
几个大号共享库组成opencv_*
的共享库组成在通过源码编译时,opencv的所有依赖会连带着一起被编译进opencv库里面,所以你所得的共享库都会比用apt install
的更大。
(上面是用apt install
的opencv,下面是我自己编译的)
第一种情况:opencv_world
是一堆常用的opencv模块集合成的库。像是Windows的opencv发行版用的就是这种形式。
第二种情况:那堆opencv_*
的共享库就是opencv的不同模块单独拆开的库,也就是你上面图片中那种。
但实际上,这个项目根本用不到全部的opencv模块,它只需要用opencv_core
,opencv_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的版本信息:
Windows(这里的opencv_world是启用的)
General configuration for OpenCV 4.9.0 =====================================
Version control: unknown
Extra modules:
Location (extra): C:/opencv-4.9.0/opencv_contrib-4.9.0/modules
Version control (extra): unknown
Platform:
Timestamp: 2024-01-28T04:53:11Z
Host: Windows 10.0.22621 AMD64
CMake: 3.28.1
CMake generator: Visual Studio 17 2022
CMake build tool: C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe
MSVC: 1934
Configuration: Debug 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 (16 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 (8 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
AVX2 (36 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
AVX512_SKX (5 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: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe (ver 19.34.31935.0)
C++ flags (Release): /DWIN32 /D_WINDOWS /W4 /GR /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819 /MP /O2 /Ob2 /DNDEBUG
C++ flags (Debug): /DWIN32 /D_WINDOWS /W4 /GR /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /wd4819 /MP /Zi /Ob0 /Od /RTC1
C Compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.34.31933/bin/Hostx64/x64/cl.exe
C flags (Release): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /MP /O2 /Ob2 /DNDEBUG
C flags (Debug): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /MP /Zi /Ob0 /Od /RTC1
Linker flags (Release): /machine:x64 /INCREMENTAL:NO
Linker flags (Debug): /machine:x64 /debug /INCREMENTAL
ccache: NO
Precompiled headers: NO
Extra dependencies:
3rdparty dependencies:
OpenCV modules:
To be built: alphamat aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab wechat_qrcode world xfeatures2d ximgproc xobjdetect xphoto
Disabled: -
Disabled by dependency: -
Unavailable: cannops cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype hdf java julia matlab ovis python2 python3 sfm ts viz
Applications: apps
Documentation: NO
Non-free algorithms: YES
Windows RT support: NO
GUI:
Win32 UI: YES
VTK support: NO
Media I/O:
ZLib: build (ver 1.3)
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.2.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: YES (prebuilt binaries)
avcodec: YES (58.134.100)
avformat: YES (58.76.100)
avutil: YES (56.70.100)
swscale: YES (5.9.100)
avresample: YES (4.0.0)
GStreamer: NO
DirectShow: YES
Media Foundation: YES
DXVA: YES
Parallel framework: Concurrency
Trace: YES (with Intel ITT)
Other third-party libraries:
Intel IPP: 2021.11.0 [2021.11.0]
at: C:/opencv-4.9.0/build_opencv/3rdparty/ippicv/ippicv_win/icv
Intel IPP IW: sources (2021.11.0)
at: C:/opencv-4.9.0/build_opencv/3rdparty/ippicv/ippicv_win/iw
Lapack: NO
Eigen: YES (ver 3.4.0)
Custom HAL: NO
Protobuf: build (3.19.1)
Flatbuffers: builtin/3rdparty (23.5.9)
OpenCL: YES (NVD3D11)
Include path: C:/opencv-4.9.0/opencv-4.9.0/3rdparty/include/opencl/1.2
Link libraries: Dynamic load
Python (for build): C:/Users/user/AppData/Local/Programs/Python/Python311/python.exe
Java:
ant: NO
Java: YES (ver 17.0.5)
JNI: C:/Program Files/Java/jdk-17.0.5/include C:/Program Files/Java/jdk-17.0.5/include/win32 C:/Program Files/Java/jdk-17.0.5/include
Java wrappers: NO
Java tests: NO
Install to: C:/opencv-4.9.0/build_opencv/install
-----------------------------------------------------------------
Linux
General configuration for OpenCV 4.9.0 =====================================
Version control: unknown
Extra modules:
Location (extra): /opencv/opencv_contrib-4.9.0/modules
Version control (extra): unknown
Platform:
Timestamp: 2024-03-07T13:08:51Z
Host: Linux 5.15.90.1-microsoft-standard-WSL2 x86_64
CMake: 3.22.1
CMake generator: Unix Makefiles
CMake build tool: /usr/bin/gmake
Configuration: RelWithDebInfo
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 (16 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 (8 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
AVX2 (36 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
AVX512_SKX (5 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: alphamat aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
Disabled: world
Disabled by dependency: -
Unavailable: cannops cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype hdf java julia matlab ovis python2 python3 sfm ts viz
Applications: apps
Documentation: NO
Non-free algorithms: YES
GUI: NONE
GTK+: NO
VTK support: NO
Media I/O:
ZLib: zlib (ver 1.3)
JPEG: libjpeg-turbo (ver 2.1.3-62)
WEBP: build (ver encoder: 0x020f)
PNG: build (ver 1.6.37)
TIFF: build (ver 42 - 4.2.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: 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.10.0 [2021.10.0]
at: /opencv/opencv-4.9.0/build/3rdparty/ippicv/ippicv_lnx/icv
Intel IPP IW: sources (2021.10.0)
at: /opencv/opencv-4.9.0/build/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: /opencv/opencv-4.9.0/3rdparty/include/opencl/1.2
Link libraries: Dynamic load
Python (for build): /usr/bin/python3
Java:
ant: /bin/ant (ver 1.10.12)
Java: NO
JNI: NO
Java wrappers: NO
Java tests: NO
Install to: /usr/local
-----------------------------------------------------------------
我更新了一下这个arc-opencv仓库,重新编译了一个禁用opencv_world
的Windows opencv,然后更新了一下我用的cmake参数和opencv General Configuration
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
得到了体积更小的包:
构建 PaddleOCR-json ,打包后的体积也更小。
不过,我有点担心在某些平台上,这样是否会缺失依赖项。还需要进一步测试。
另外,你release中 lib/libgomp.so.1
是什么的依赖文件?它是必要的吗?
不过,我有点担心在某些平台上,这样是否会缺失依赖项。
这个只能多测试了,我是直接开一个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自己要好,建议这俩选一个。
我不建议把这几个给关掉
我简单测试了一下。
DWITH_IPP
、DBUILD_IPP_IW
、DWITH_LAPACK
设为 ON
或 OFF
,编译出的包,OCR速度几乎没有差别。OFF时包体积更小。(我想,开销的大头可能在模型库推理,图像处理的复杂度占比不高)enable_mkldnn
启用/不启用,OCR速度几乎没有差别。(而在Windows上,关闭mkl会慢数倍。)上述测试是在 Intel W7-3445
服务器上进行的。跟 Windows i5 13600K
相比,Linux服务器平均慢50%。(两个平台下,PaddleOCR-json 的线程数都设为12)
我想这种性能差距有两种可能:
(在服务器下为 PaddleOCR-json 设置更多的线程数,比如20,也是不可行的,处理速度反而会更慢。)
这是我手上编译的几个libopencv_core的对比:
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
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/
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
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'))
好建议,收到。
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_FORCE_3RDPARTY_BUILD
强制编译所有第三方组件。这样可以避免在新安装的debian12上出现 error while loading shared libraries: libIlmImf-2_5.so.25
等报错。LAPACK
和 EIGEN
:我查了下,这两个选项不会冲突,应该可以同时开启。而且对生成文件体积没有影响。你可以帮我试下,如果没问题的话,就用这组参数和生成的文件作为基准。
感觉没问题。我测试了一下,把成品的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 \
下面是我编译出来的共享库大小(用了你的参数+上面这两行)
还有一个问题是,尽管我已经安装libeigen3-dev
和liblapack-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
-----------------------------------------------------------------
了解✓
另外,我觉得v1.4.0差不多可以发正式版了,你还有没有需改动的地方?
过几天Umi也会发个新版本,附带这边的v1.4.0。
希望增加方向分类的输出,用于纠正图像的方向
希望增加方向分类的输出,用于纠正图像的方向
代码改起来不难。
但是,PPOCR的模型中,方向分类cls只是一个 0 或 1 的值。0表示文字是正朝上或顺时针90°,1表示文字是朝下或逆时针90°。对于OCR模型,知道这个值,就足够纠正文字识别了。
但是,用户就没办法知道文字的具体角度,也没办法判断是正朝上还是顺时针旋转了角度。
这样能满足你的需求吗?
要添加的话,只需要在 task.cpp
第91行之前,
添加以下语句:
// 写入方向分类相关参数
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 两个参数。
方向分类cls只是一个 0 或 1 的值。0表示文字是正朝上或顺时针90°,1表示文字是朝下或逆时针90°。
增加这两个就行了,具体怎么解决方向问题我再研究研究
我调整一下,明天重新打个包
建议以后打包发行时不要用7zip
7zip的压缩包不会保存unix系统的文件权限,这很容易出错。
像上面这样,7zip发行压缩包在解压后丢失了PaddleOCR-json可执行程序的执行权限(run.sh的权限还在),这时运行run.sh的话就会报错Permission denied。
这种情况时有时无,不过换成zip就行了。