Skip to content

📄 Awesome OCR multiple programing languages toolkits based on ONNX Runtime, OpenVINO, MNN, PaddlePaddle, TensorRT and PyTorch.

c++项目升级v1.0.1,添加文件不存在时的容错处理,修改测试脚本,优化代码

benjaminwan2a7296a079aa
diff --git a/cpp/BaiPiaoOcrOnnx/.gitignore b/cpp/BaiPiaoOcrOnnx/.gitignore
index eb27c5e..42a7ba6 100644
--- a/cpp/BaiPiaoOcrOnnx/.gitignore
+++ b/cpp/BaiPiaoOcrOnnx/.gitignore
@@ -135,7 +135,8 @@ dmypy.json
cmake-build-debug/
build/
build-lib/
-/models/
+models/
+images/
onnxruntime-shared/
onnxruntime-static/
opencv-static/
diff --git a/cpp/BaiPiaoOcrOnnx/CMakeLists.txt b/cpp/BaiPiaoOcrOnnx/CMakeLists.txt
index 5ff7c20..44c6598 100644
--- a/cpp/BaiPiaoOcrOnnx/CMakeLists.txt
+++ b/cpp/BaiPiaoOcrOnnx/CMakeLists.txt
@@ -1,14 +1,14 @@
cmake_minimum_required(VERSION 3.1)
project(BaiPiaoOcrOnnx)
-option(BAIPIAO_LIB "OcrLite Jni Support" OFF)
-option(BAIPIAO_STATIC "Use Static Librarys For Build" ON)
-option(BAIPIAO_OPENMP "OcrLite Enable OpenMP" ON)
-option(BAIPIAO_BENCHMARK "build benchmark" ON)
-#set(BAIPIAO_LIB ON)
-#set(BAIPIAO_STATIC OFF)
-#set(BAIPIAO_OPENMP OFF)
-set(BAIPIAO_BENCHMARK ON)
+option(OCR_LIB "OcrLite Jni Support" OFF)
+option(OCR_STATIC "Use Static Librarys For Build" ON)
+option(OCR_OPENMP "OcrLite Enable OpenMP" ON)
+option(OCR_BENCHMARK "build benchmark" ON)
+#set(OCR_LIB ON)
+#set(OCR_STATIC OFF)
+#set(OCR_OPENMP OFF)
+set(OCR_BENCHMARK ON)
set(CMAKE_CXX_STANDARD 11)
add_definitions(-DUNICODE -D_UNICODE)
@@ -47,7 +47,7 @@ else ()
endif ()
# OnnxRuntime
-if (BAIPIAO_STATIC)
+if (OCR_STATIC)
set(OnnxRuntime_DIR "${CMAKE_CURRENT_SOURCE_DIR}/onnxruntime-static")
else ()
set(OnnxRuntime_DIR "${CMAKE_CURRENT_SOURCE_DIR}/onnxruntime-shared")
@@ -61,7 +61,7 @@ else ()
endif (OnnxRuntime_FOUND)
# OpenCV
-if (BAIPIAO_STATIC)
+if (OCR_STATIC)
include(${CMAKE_CURRENT_SOURCE_DIR}/opencv-static/OpenCVWrapperConfig.cmake)
else ()
include(${CMAKE_CURRENT_SOURCE_DIR}/opencv-shared/OpenCVWrapperConfig.cmake)
@@ -75,7 +75,7 @@ else ()
endif (OpenCV_FOUND)
# JNI
-if (BAIPIAO_LIB)
+if (OCR_LIB)
find_package(JNI REQUIRED)
if (JNI_FOUND)
message("JNI FOUND")
@@ -94,7 +94,16 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
file(GLOB OCR_SRC ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
set(OCR_COMPILE_CODE ${OCR_SRC})
-if (BAIPIAO_LIB)
+# static libgcc libstdc++
+if (OCR_STATIC)
+ if (APPLE)
+ set(CMAKE_EXE_LINKER_FLAGS "-static-libstdc++")
+ else ()
+ set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++")
+ endif ()
+endif ()
+
+if (OCR_LIB)
add_library(BaiPiaoOcrOnnx SHARED ${OCR_COMPILE_CODE})
target_compile_definitions(BaiPiaoOcrOnnx PRIVATE __JNI__)
target_link_libraries(BaiPiaoOcrOnnx ${OnnxRuntime_LIBS} ${OpenCV_LIBS} ${JNI_LIBS} ${OpenMP_CXX_LIB_NAMES})
@@ -102,12 +111,13 @@ else ()
add_executable(BaiPiaoOcrOnnx ${OCR_COMPILE_CODE})
target_link_libraries(BaiPiaoOcrOnnx ${OnnxRuntime_LIBS} ${OpenCV_LIBS} ${OpenMP_CXX_LIB_NAMES})
endif ()
-if (BAIPIAO_OPENMP)
+
+if (OCR_OPENMP)
target_compile_definitions(BaiPiaoOcrOnnx PRIVATE __OPENMP__)
endif ()
# benchmark
-if (BAIPIAO_BENCHMARK AND NOT BAIPIAO_LIB)
+if (OCR_BENCHMARK AND NOT OCR_LIB)
add_executable(benchmark benchmark/benchmark.cpp
src/AngleNet.cpp
src/clipper.cpp
@@ -117,7 +127,7 @@ if (BAIPIAO_BENCHMARK AND NOT BAIPIAO_LIB)
src/OcrLite.cpp
src/OcrUtils.cpp)
target_link_libraries(benchmark ${OnnxRuntime_LIBS} ${OpenCV_LIBS} ${OpenMP_CXX_LIB_NAMES})
- if (BAIPIAO_OPENMP)
+ if (OCR_OPENMP)
target_compile_definitions(benchmark PRIVATE __OPENMP__)
endif ()
endif ()
\ No newline at end of file
diff --git a/cpp/BaiPiaoOcrOnnx/README.md b/cpp/BaiPiaoOcrOnnx/README.md
index 80b5e14..97a1318 100644
--- a/cpp/BaiPiaoOcrOnnx/README.md
+++ b/cpp/BaiPiaoOcrOnnx/README.md
@@ -48,7 +48,8 @@ BaiPiaoOcrOnnx
### 编译环境
1. Windows 10 x64
2. macOS 10.15
-3. Linux Ubuntu 1604
+3. Linux Ubuntu 1604 x64
+**注意:以下说明仅适用于本机编译。如果需要交叉编译为arm等其它平台(参考android),则需要先交叉编译所有第三方依赖库(onnxruntime、opencv),然后再把依赖库整合替换到本项目里。**
### Windows编译说明
#### Windows nmake编译
@@ -56,7 +57,7 @@ BaiPiaoOcrOnnx
2. cmake请自行下载&配置,[下载地址](https://cmake.org/download/)
3. 开始菜单打开"x64 Native Tools Command Prompt for VS 2019"或"适用于 VS2017 的 x64 本机工具",并转到本项目根目录
4. 运行```build.bat```并按照提示输入选项,最后选择'编译成可执行文件'
-5. 编译完成后运行```run-test.bat```进行测试
+5. 编译完成后运行```run-test.bat```进行测试(注意修改脚本内的目标图片路径)
6. 编译JNI动态运行库(可选,可用于java调用)
* 下载jdk-8u221-windows-x64.exe,安装选项默认(确保“源代码”项选中),安装完成后,打开“系统”属性->高级->环境变量
* 新建“系统变量”,变量名```JAVA_HOME``` ,变量值```C:\Program Files\Java\jdk1.8.0_221``
@@ -81,7 +82,7 @@ BaiPiaoOcrOnnx
2. 自行下载安装HomeBrew,cmake >=3.1[下载地址](https://cmake.org/download/)
3. libomp: ```brew install libomp```
4. 终端打开项目根目录,```./build.sh```并按照提示输入选项,最后选择'编译成可执行文件'
-5. 测试:```./run-test.sh```
+5. 测试:```./run-test.sh```(注意修改脚本内的目标图片路径)
6. 编译JNI动态运行库(可选,可用于java调用)
* 下载jdk-8u221-macosx-x64.dmg,安装。
* 编辑用户目录下的隐藏文件```.zshrc``` ,添加```export JAVA_HOME=$(/usr/libexec/java_home)```
@@ -97,7 +98,7 @@ opencv或onnxruntime使用动态库时,参考下列方法:
2. ```sudo apt-get install build-essential```
3. g++>=5,cmake>=3.1[下载地址](https://cmake.org/download/)
4. 终端打开项目根目录,```./build.sh```并按照提示输入选项,最后选择'编译成可执行文件'
-5. 测试:```./run-test.sh```
+5. 测试:```./run-test.sh```(注意修改脚本内的目标图片路径)
6. 编译JNI动态运行库(可选,可用于java调用)
* 下载jdk-8u221并安装配置
* 运行```build.sh```并按照提示输入选项,最后选择'编译成JNI动态库'
@@ -109,25 +110,25 @@ opencv或onnxruntime使用动态库时,参考下列方法:
### 编译参数说明
build.sh编译参数:
-1. ```BAIPIAO_OPENMP=ON```:启用(ON)或禁用(OFF) ON时AngleNet和CrnnNet阶段使用OpenMP并行运算,OFF时单线程运算
-2. ```BAIPIAO_LIB=ON```: 启用(ON)或禁用(OFF) ON时编译为jni lib,OFF时编译为可执行文件
-3. ```BAIPIAO_STATIC=ON```: 启用(ON)或禁用(OFF) ON时选择opencv和onnxruntime的静态库进行编译,OFF时则选择动态库编译
+1. ```OCR_OPENMP=ON```:启用(ON)或禁用(OFF) ON时AngleNet和CrnnNet阶段使用OpenMP并行运算,OFF时单线程运算
+2. ```OCR_LIB=ON```: 启用(ON)或禁用(OFF) ON时编译为jni lib,OFF时编译为可执行文件
+3. ```OCR_STATIC=ON```: 启用(ON)或禁用(OFF) ON时选择opencv和onnxruntime的静态库进行编译,OFF时则选择动态库编译
### 输入参数说明
* 请参考main.h中的命令行参数说明。
* 每个参数有一个短参数名和一个长参数名,用短的或长的均可。
1. ```-d或--models```:模型所在文件夹路径,可以相对路径也可以绝对路径。
-2. ```-1或--det```:det模型文件名
-3. ```-2或--cls```:cls模型文件名
-4. ```-3或--rec```:rec模型文件名
-5. ```-4或--keys```:keys.txt文件名
+2. ```-1或--det```:det模型文件名(含扩展名)
+3. ```-2或--cls```:cls模型文件名(含扩展名)
+4. ```-3或--rec```:rec模型文件名(含扩展名)
+5. ```-4或--keys```:keys.txt文件名(含扩展名)
6. ```-i或--image```:目标图片路径,可以相对路径也可以绝对路径。
7. ```-t或--numThread```:线程数量。
8. ```-p或--padding```:图像预处理,在图片外周添加白边,用于提升识别率,文字框没有正确框住所有文字时,增加此值。
9. ```-s或--maxSideLen```:按图片最长边的长度,此值为0代表不缩放,例:1024,如果图片长边大于1024则把图像整体缩小到1024再进行图像分割计算,如果图片长边小于1024则不缩放,如果图片长边小于32,则缩放到32。
-6. ```-b或--boxScoreThresh```:文字框置信度门限,文字框没有正确框住所有文字时,减小此值。
-7. ```-o或--boxThresh```:请自行试验。
-9. ```-u或--unClipRatio```:单个文字框大小倍率,越大时单个文字框越大。此项与图片的大小相关,越大的图片此值应该越大。
-10. ```-a或--noAngle```:启用(1)/禁用(0) 文字方向检测,只有图片倒置的情况下(旋转90~270度的图片),才需要启用文字方向检测。
-11. ```-A或--mostAngle```:启用(1)/禁用(0) 角度投票(整张图片以最大可能文字方向来识别),当禁用文字方向检测时,此项也不起作用。
-12. ```-?或--help```:打印命令行帮助。
+10. ```-b或--boxScoreThresh```:文字框置信度门限,文字框没有正确框住所有文字时,减小此值。
+11. ```-o或--boxThresh```:请自行试验。
+12. ```-u或--unClipRatio```:单个文字框大小倍率,越大时单个文字框越大。此项与图片的大小相关,越大的图片此值应该越大。
+13. ```-a或--doAngle```:启用(1)/禁用(0) 文字方向检测,只有图片倒置的情况下(旋转90~270度的图片),才需要启用文字方向检测。
+14. ```-A或--mostAngle```:启用(1)/禁用(0) 角度投票(整张图片以最大可能文字方向来识别),当禁用文字方向检测时,此项也不起作用。
+15. ```-h或--help```:打印命令行帮助。
diff --git a/cpp/BaiPiaoOcrOnnx/benchmark/benchmark.cpp b/cpp/BaiPiaoOcrOnnx/benchmark/benchmark.cpp
index 2f0d875..3e19430 100644
--- a/cpp/BaiPiaoOcrOnnx/benchmark/benchmark.cpp
+++ b/cpp/BaiPiaoOcrOnnx/benchmark/benchmark.cpp
@@ -1,9 +1,9 @@
#include <omp.h>
#include <cstdio>
-#include <string>
#include "main.h"
#include "version.h"
#include "OcrLite.h"
+#include "OcrUtils.h"
void printHelp(FILE *out, char *argv0) {
fprintf(out, " ------- Usage -------\n");
@@ -24,10 +24,8 @@ int main(int argc, char **argv) {
printHelp(stderr, argv[0]);
return -1;
}
- std::string modelsDir = "../models";
- std::string modelDetPath, modelClsPath, modelRecPath, keysPath;
- std::string argImgPath = "../../test_imgs/1.jpg";
- std::string imgPath, imgName;
+ std::string modelsDir, modelDetPath, modelClsPath, modelRecPath, keysPath;
+ std::string imgPath, imgDir, imgName;
int numThread = 4;
int loopCount = 1;
int padding = 0;
@@ -37,8 +35,8 @@ int main(int argc, char **argv) {
float unClipRatio = 2.0f;
bool doAngle = true;
int flagDoAngle = 1;
- bool mostAngle = false;
- int flagMostAngle = 0;
+ bool mostAngle = true;
+ int flagMostAngle = 1;
int opt;
int optionIndex = 0;
@@ -66,10 +64,10 @@ int main(int argc, char **argv) {
printf("keys path=%s\n", keysPath.c_str());
break;
case 'i':
- argImgPath.assign(optarg);
- imgPath.assign(argImgPath.substr(0, argImgPath.find_last_of('/') + 1));
- imgName.assign(argImgPath.substr(argImgPath.find_last_of('/') + 1));
- printf("imgPath=%s, imgName=%s\n", imgPath.c_str(), imgName.c_str());
+ imgPath.assign(optarg);
+ imgDir.assign(imgPath.substr(0, imgPath.find_last_of('/') + 1));
+ imgName.assign(imgPath.substr(imgPath.find_last_of('/') + 1));
+ printf("imgDir=%s, imgName=%s\n", imgDir.c_str(), imgName.c_str());
break;
case 't':
numThread = (int) strtol(optarg, NULL, 10);
@@ -127,7 +125,31 @@ int main(int argc, char **argv) {
printf("other option %c :%s\n", opt, optarg);
}
}
-
+ bool hasTargetImgFile = isFileExists(imgPath);
+ if (!hasTargetImgFile) {
+ fprintf(stderr, "Target image not found: %s\n", imgPath.c_str());
+ return -1;
+ }
+ bool hasModelDetFile = isFileExists(modelDetPath);
+ if (!hasModelDetFile) {
+ fprintf(stderr, "Model det file not found: %s\n", modelDetPath.c_str());
+ return -1;
+ }
+ bool hasModelClsFile = isFileExists(modelClsPath);
+ if (!hasModelClsFile) {
+ fprintf(stderr, "Model cls file not found: %s\n", modelClsPath.c_str());
+ return -1;
+ }
+ bool hasModelRecFile = isFileExists(modelRecPath);
+ if (!hasModelRecFile) {
+ fprintf(stderr, "Model rec file not found: %s\n", modelRecPath.c_str());
+ return -1;
+ }
+ bool hasKeysFile = isFileExists(keysPath);
+ if (!hasKeysFile) {
+ fprintf(stderr, "keys file not found: %s\n", keysPath.c_str());
+ return -1;
+ }
omp_set_num_threads(numThread);
OcrLite ocrLite;
ocrLite.setNumThread(numThread);
@@ -136,7 +158,7 @@ int main(int argc, char **argv) {
false,//isOutputPartImg
false);//isOutputResultImg
- ocrLite.enableResultTxt(imgPath.c_str(), imgName.c_str());
+ //ocrLite.enableResultTxt(imgDir.c_str(), imgName.c_str());
printf("=====Input Params=====\n");
printf(
"numThread(%d),padding(%d),maxSideLen(%d),boxScoreThresh(%f),boxThresh(%f),unClipRatio(%f),doAngle(%d),mostAngle(%d)\n",
@@ -144,14 +166,14 @@ int main(int argc, char **argv) {
ocrLite.initModels(modelDetPath, modelClsPath, modelRecPath, keysPath);
printf("=====warmup=====\n");
- OcrResult result = ocrLite.detect(imgPath.c_str(), imgName.c_str(), padding, maxSideLen,
+ OcrResult result = ocrLite.detect(imgDir.c_str(), imgName.c_str(), padding, maxSideLen,
boxScoreThresh, boxThresh, unClipRatio, doAngle, mostAngle);
printf("dbNetTime(%f) detectTime(%f)\n", result.dbNetTime, result.detectTime);
double dbTime = 0.0f;
double detectTime = 0.0f;
for (int i = 0; i < loopCount; ++i) {
printf("=====loop:%d=====\n", i + 1);
- OcrResult ocrResult = ocrLite.detect(imgPath.c_str(), imgName.c_str(),
+ OcrResult ocrResult = ocrLite.detect(imgDir.c_str(), imgName.c_str(),
padding, maxSideLen,
boxScoreThresh, boxThresh,
unClipRatio, doAngle, mostAngle);
diff --git a/cpp/BaiPiaoOcrOnnx/build.bat b/cpp/BaiPiaoOcrOnnx/build.bat
index 1574d1c..9a487fa 100755
--- a/cpp/BaiPiaoOcrOnnx/build.bat
+++ b/cpp/BaiPiaoOcrOnnx/build.bat
@@ -43,8 +43,8 @@ else (echo 输入错误!Input Error!)
echo.
if %BUILD_LIB% == OFF (call :makeExe)^
else (call :makeLib)
-echo cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DBAIPIAO_OPENMP=%BUILD_OPENMP% -DBAIPIAO_LIB=%BUILD_LIB% -DBAIPIAO_STATIC=%BUILD_STATIC% ..
-cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DBAIPIAO_OPENMP=%BUILD_OPENMP% -DBAIPIAO_LIB=%BUILD_LIB% -DBAIPIAO_STATIC=%BUILD_STATIC% ..
+echo cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DOCR_OPENMP=%BUILD_OPENMP% -DOCR_LIB=%BUILD_LIB% -DOCR_STATIC=%BUILD_STATIC% ..
+cmake -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=%BUILD_TYPE% -DOCR_OPENMP=%BUILD_OPENMP% -DOCR_LIB=%BUILD_LIB% -DOCR_STATIC=%BUILD_STATIC% ..
nmake
popd
GOTO:EOF
diff --git a/cpp/BaiPiaoOcrOnnx/build.sh b/cpp/BaiPiaoOcrOnnx/build.sh
index 56450e8..bfac806 100755
--- a/cpp/BaiPiaoOcrOnnx/build.sh
+++ b/cpp/BaiPiaoOcrOnnx/build.sh
@@ -67,7 +67,7 @@ else
echo "Other OS: $sysOS"
fi
-echo "cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DBAIPIAO_OPENMP=${BUILD_OPENMP} -DBAIPIAO_LIB=${BUILD_LIB} -DBAIPIAO_STATIC=${BUILD_STATIC} .."
-cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DBAIPIAO_OPENMP=$BUILD_OPENMP -DBAIPIAO_LIB=$BUILD_LIB -DBAIPIAO_STATIC=$BUILD_STATIC ..
+echo "cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} -DOCR_OPENMP=${BUILD_OPENMP} -DOCR_LIB=${BUILD_LIB} -DOCR_STATIC=${BUILD_STATIC} .."
+cmake -DCMAKE_BUILD_TYPE=$BUILD_TYPE -DOCR_OPENMP=$BUILD_OPENMP -DOCR_LIB=$BUILD_LIB -DOCR_STATIC=$BUILD_STATIC ..
make -j $NUM_THREADS
popd
\ No newline at end of file
diff --git a/cpp/BaiPiaoOcrOnnx/generate-vs-project.bat b/cpp/BaiPiaoOcrOnnx/generate-vs-project.bat
index a6eae27..741e034 100755
--- a/cpp/BaiPiaoOcrOnnx/generate-vs-project.bat
+++ b/cpp/BaiPiaoOcrOnnx/generate-vs-project.bat
@@ -88,8 +88,8 @@ popd
GOTO:EOF
:cmakeParams
-echo cmake -G "%~1" -A "%~2" -DBAIPIAO_OPENMP=%BUILD_OPENMP% -DBAIPIAO_LIB=%BUILD_LIB% -DBAIPIAO_STATIC=%BUILD_STATIC% ..
-cmake -G "%~1" -A "%~2" -DBAIPIAO_OPENMP=%BUILD_OPENMP% -DBAIPIAO_LIB=%BUILD_LIB% -DBAIPIAO_STATIC=%BUILD_STATIC% ..
+echo cmake -G "%~1" -A "%~2" -DOCR_OPENMP=%BUILD_OPENMP% -DOCR_LIB=%BUILD_LIB% -DOCR_STATIC=%BUILD_STATIC% ..
+cmake -G "%~1" -A "%~2" -DOCR_OPENMP=%BUILD_OPENMP% -DOCR_LIB=%BUILD_LIB% -DOCR_STATIC=%BUILD_STATIC% ..
GOTO:EOF
@ENDLOCAL
diff --git a/cpp/BaiPiaoOcrOnnx/include/DbNet.h b/cpp/BaiPiaoOcrOnnx/include/DbNet.h
index 0f5bce0..10ffa17 100644
--- a/cpp/BaiPiaoOcrOnnx/include/DbNet.h
+++ b/cpp/BaiPiaoOcrOnnx/include/DbNet.h
@@ -26,8 +26,8 @@ private:
std::vector<char *> inputNames;
std::vector<char *> outputNames;
- const float meanValues[3] = {0.485f * 255, 0.456f * 255, 0.406f * 255};
- const float normValues[3] = {1.0 / 0.229f / 255.0, 1.0 / 0.224f / 255.0, 1.0 / 0.225f / 255.0};
+ const float meanValues[3] = {0.485 * 255, 0.456 * 255, 0.406 * 255};
+ const float normValues[3] = {1.0 / 0.229 / 255.0, 1.0 / 0.224 / 255.0, 1.0 / 0.225 / 255.0};
};
diff --git a/cpp/BaiPiaoOcrOnnx/include/OcrUtils.h b/cpp/BaiPiaoOcrOnnx/include/OcrUtils.h
index 260cac9..4d49ae7 100644
--- a/cpp/BaiPiaoOcrOnnx/include/OcrUtils.h
+++ b/cpp/BaiPiaoOcrOnnx/include/OcrUtils.h
@@ -5,6 +5,7 @@
#include "OcrStruct.h"
#include "onnxruntime_cxx_api.h"
#include <numeric>
+#include <sys/stat.h>
template<typename T, typename... Ts>
static std::unique_ptr<T> makeUnique(Ts &&... params) {
@@ -39,6 +40,11 @@ inline T clamp(T x, T min, T max) {
double getCurrentTime();
+inline bool isFileExists(const std::string &name) {
+ struct stat buffer;
+ return (stat(name.c_str(), &buffer) == 0);
+}
+
std::wstring strToWstr(std::string str);
ScaleParam getScaleParam(cv::Mat &src, const float scale);
diff --git a/cpp/BaiPiaoOcrOnnx/include/main.h b/cpp/BaiPiaoOcrOnnx/include/main.h
index b8826d0..c42d425 100755
--- a/cpp/BaiPiaoOcrOnnx/include/main.h
+++ b/cpp/BaiPiaoOcrOnnx/include/main.h
@@ -33,21 +33,22 @@ const char *requiredMsg = "-d --models: models directory.\n" \
"-1 --det: model file name of det.\n" \
"-2 --cls: model file name of cls.\n" \
"-3 --rec: model file name of rec.\n" \
+ "-4 --keys: keys file name.\n" \
"-i --image: path of target image.\n\n";
const char *optionalMsg = "-t --numThread: value of numThread(int), default: 4\n" \
- "-p --padding: value of padding(int), default: 50\n" \
+ "-p --padding: value of padding(int), default: 0\n" \
"-s --maxSideLen: Long side of picture for resize(int), default: 1024\n" \
"-b --boxScoreThresh: value of boxScoreThresh(float), default: 0.5\n" \
"-o --boxThresh: value of boxThresh(float), default: 0.3\n" \
"-u --unClipRatio: value of unClipRatio(float), default: 2.0\n" \
"-a --doAngle: Enable(1)/Disable(0) Angle Net, default: Enable\n" \
- "-A --mostAngle: Enable(1)/Disable(0) Most Possible AngleIndex, default: Disable\n\n";
+ "-A --mostAngle: Enable(1)/Disable(0) Most Possible AngleIndex, default: Enable\n\n";
const char *otherMsg = "-v --version: show version\n" \
"-h --help: print this help\n\n";
-const char *example1Msg = "Example1: %s --models models --det det.onnx --cls cls.onnx --rec rec.onnx --image 1.jpg\n";
-const char *example2Msg = "Example2: %s -d models -1 det.onnx -2 cls.onnx -3 rec.onnx -i 1.jpg -t 4 -p 50 -s 0 -b 0.6 -o 0.3 -u 2.0 -a 1 -A 1\n";
+const char *example1Msg = "Example1: %s --models models --det det.onnx --cls cls.onnx --rec rec.onnx --keys keys.txt --image 1.jpg\n";
+const char *example2Msg = "Example2: %s -d models -1 det.onnx -2 cls.onnx -3 rec.onnx -4 keys.txt -i 1.jpg -t 4 -p 50 -s 0 -b 0.6 -o 0.3 -u 2.0 -a 1 -A 1\n";
#endif //__MAIN_H__
diff --git a/cpp/BaiPiaoOcrOnnx/include/version.h b/cpp/BaiPiaoOcrOnnx/include/version.h
index 30db6f5..7969150 100644
--- a/cpp/BaiPiaoOcrOnnx/include/version.h
+++ b/cpp/BaiPiaoOcrOnnx/include/version.h
@@ -1,6 +1,6 @@
#ifndef __OCR_VERSION_H__
#define __OCR_VERSION_H__
-#define VERSION "1.0.0"
+#define VERSION "1.0.1"
#endif //__OCR_VERSION_H__
diff --git a/cpp/BaiPiaoOcrOnnx/run-benchmark.bat b/cpp/BaiPiaoOcrOnnx/run-benchmark.bat
index 87c7773..d7a63ad 100755
--- a/cpp/BaiPiaoOcrOnnx/run-benchmark.bat
+++ b/cpp/BaiPiaoOcrOnnx/run-benchmark.bat
@@ -7,20 +7,28 @@ set OMP_NUM_THREADS=%NUMBER_OF_PROCESSORS%
echo "请选择det模型: 1)server, 2)mobile"
set /p flag=
-if %flag% == 1 (set DET_MODEL="ch_ppocr_server_v2.0_det_infer.onnx")^
-else if %flag% == 2 (set DET_MODEL="ch_ppocr_mobile_v2.0_det_infer.onnx")^
+if %flag% == 1 (set DET_MODEL=ch_ppocr_server_v2.0_det_infer.onnx)^
+else if %flag% == 2 (set DET_MODEL=ch_ppocr_mobile_v2.0_det_infer.onnx)^
else (echo 输入错误!Input Error!)
echo "请输入循环次数:"
set /p LOOP_COUNT=
+SET TARGET_IMG=images/1.jpg
+if not exist %TARGET_IMG% (
+echo "找不到待识别的目标图片:%TARGET_IMG%,请打开本文件并编辑TARGET_IMG"
+PAUSE
+exit
+)
+
:: run Windows
+build\benchmark.exe --version
build\benchmark.exe --models models ^
--det %DET_MODEL% ^
--cls ch_ppocr_mobile_v2.0_cls_infer.onnx ^
--rec ch_ppocr_server_v2.0_rec_infer.onnx ^
--keys ppocr_keys_v1.txt ^
---image ../../images/1.jpg ^
+--image %TARGET_IMG% ^
--numThread %NUMBER_OF_PROCESSORS% ^
--padding 0 ^
--maxSideLen 1024 ^
@@ -28,7 +36,7 @@ build\benchmark.exe --models models ^
--boxThresh 0.3 ^
--unClipRatio 1.5 ^
--doAngle 1 ^
---mostAngle 0 ^
+--mostAngle 1 ^
--loopCount %LOOP_COUNT%
PAUSE
@ENDLOCAL
diff --git a/cpp/BaiPiaoOcrOnnx/run-benchmark.sh b/cpp/BaiPiaoOcrOnnx/run-benchmark.sh
index fd2c6ee..88df0c7 100755
--- a/cpp/BaiPiaoOcrOnnx/run-benchmark.sh
+++ b/cpp/BaiPiaoOcrOnnx/run-benchmark.sh
@@ -15,16 +15,33 @@ fi
echo "Setting the Number of Threads=$NUM_THREADS Using an OpenMP Environment Variable"
set OMP_NUM_THREADS=$NUM_THREADS
+echo "请选择det模型: 1)server, 2)mobile"
+read -p "" DET_MODEL
+if [ $DET_MODEL == 1 ]; then
+ DET_MODEL="ch_ppocr_server_v2.0_det_infer.onnx"
+elif [ $DET_MODEL == 2 ]; then
+ DET_MODEL="ch_ppocr_mobile_v2.0_det_infer.onnx"
+else
+ echo -e "Input Error!"
+fi
+
echo "请输入循环次数:"
read -p "" LOOP_COUNT
+TARGET_IMG=images/1.jpg
+if [ ! -f "$TARGET_IMG" ]; then
+echo "找不到待识别的目标图片:${TARGET_IMG},请打开本文件并编辑TARGET_IMG"
+exit
+fi
+
##### run test on MacOS or Linux
+./build/benchmark --version
./build/benchmark --models models \
---det ch_ppocr_server_v2.0_det_infer.onnx \
+--det $DET_MODEL \
--cls ch_ppocr_mobile_v2.0_cls_infer.onnx \
--rec ch_ppocr_server_v2.0_rec_infer.onnx \
--keys ppocr_keys_v1.txt \
---image ../../images/1.jpg \
+--image $TARGET_IMG \
--numThread $NUM_THREADS \
--padding 0 \
--maxSideLen 1024 \
@@ -32,5 +49,5 @@ read -p "" LOOP_COUNT
--boxThresh 0.3 \
--unClipRatio 1.5 \
--doAngle 1 \
---mostAngle 0 \
+--mostAngle 1 \
--loopCount $LOOP_COUNT
\ No newline at end of file
diff --git a/cpp/BaiPiaoOcrOnnx/run-test.bat b/cpp/BaiPiaoOcrOnnx/run-test.bat
index 404234e..09ba746 100755
--- a/cpp/BaiPiaoOcrOnnx/run-test.bat
+++ b/cpp/BaiPiaoOcrOnnx/run-test.bat
@@ -7,17 +7,25 @@ set OMP_NUM_THREADS=%NUMBER_OF_PROCESSORS%
echo "请选择det模型: 1)server, 2)mobile"
set /p flag=
-if %flag% == 1 (set DET_MODEL="ch_ppocr_server_v2.0_det_infer.onnx")^
-else if %flag% == 2 (set DET_MODEL="ch_ppocr_mobile_v2.0_det_infer.onnx")^
+if %flag% == 1 (set DET_MODEL=ch_ppocr_server_v2.0_det_infer.onnx)^
+else if %flag% == 2 (set DET_MODEL=ch_ppocr_mobile_v2.0_det_infer.onnx)^
else (echo 输入错误!Input Error!)
+SET TARGET_IMG=images/1.jpg
+if not exist %TARGET_IMG% (
+echo "找不到待识别的目标图片:%TARGET_IMG%,请打开本文件并编辑TARGET_IMG"
+PAUSE
+exit
+)
+
:: run Windows
+build\BaiPiaoOcrOnnx.exe --version
build\BaiPiaoOcrOnnx.exe --models models ^
--det %DET_MODEL% ^
--cls ch_ppocr_mobile_v2.0_cls_infer.onnx ^
--rec ch_ppocr_server_v2.0_rec_infer.onnx ^
--keys ppocr_keys_v1.txt ^
---image ../../images/1.jpg ^
+--image %TARGET_IMG% ^
--numThread %NUMBER_OF_PROCESSORS% ^
--padding 0 ^
--maxSideLen 1024 ^
@@ -25,6 +33,6 @@ build\BaiPiaoOcrOnnx.exe --models models ^
--boxThresh 0.3 ^
--unClipRatio 1.5 ^
--doAngle 1 ^
---mostAngle 0
+--mostAngle 1
PAUSE
@ENDLOCAL
diff --git a/cpp/BaiPiaoOcrOnnx/run-test.sh b/cpp/BaiPiaoOcrOnnx/run-test.sh
index 10275cc..d978457 100755
--- a/cpp/BaiPiaoOcrOnnx/run-test.sh
+++ b/cpp/BaiPiaoOcrOnnx/run-test.sh
@@ -15,13 +15,30 @@ fi
echo "Setting the Number of Threads=$NUM_THREADS Using an OpenMP Environment Variable"
set OMP_NUM_THREADS=$NUM_THREADS
+echo "请选择det模型: 1)server, 2)mobile"
+read -p "" DET_MODEL
+if [ $DET_MODEL == 1 ]; then
+ DET_MODEL="ch_ppocr_server_v2.0_det_infer.onnx"
+elif [ $DET_MODEL == 2 ]; then
+ DET_MODEL="ch_ppocr_mobile_v2.0_det_infer.onnx"
+else
+ echo -e "Input Error!"
+fi
+
+TARGET_IMG=images/1.jpg
+if [ ! -f "$TARGET_IMG" ]; then
+echo "找不到待识别的目标图片:${TARGET_IMG},请打开本文件并编辑TARGET_IMG"
+exit
+fi
+
##### run test on MacOS or Linux
+./build/BaiPiaoOcrOnnx --version
./build/BaiPiaoOcrOnnx --models models \
---det ch_ppocr_server_v2.0_det_infer.onnx \
+--det $DET_MODEL \
--cls ch_ppocr_mobile_v2.0_cls_infer.onnx \
--rec ch_ppocr_server_v2.0_rec_infer.onnx \
--keys ppocr_keys_v1.txt \
---image ../../images/1.jpg \
+--image $TARGET_IMG \
--numThread $NUM_THREADS \
--padding 0 \
--maxSideLen 1024 \
@@ -29,4 +46,4 @@ set OMP_NUM_THREADS=$NUM_THREADS
--boxThresh 0.3 \
--unClipRatio 1.5 \
--doAngle 1 \
---mostAngle 0
\ No newline at end of file
+--mostAngle 1
\ No newline at end of file
diff --git a/cpp/BaiPiaoOcrOnnx/src/AngleNet.cpp b/cpp/BaiPiaoOcrOnnx/src/AngleNet.cpp
index 575ad53..206ce70 100755
--- a/cpp/BaiPiaoOcrOnnx/src/AngleNet.cpp
+++ b/cpp/BaiPiaoOcrOnnx/src/AngleNet.cpp
@@ -98,7 +98,6 @@ std::vector<Angle> AngleNet::getAngles(std::vector<cv::Mat> &partImgs, const cha
double startAngle = getCurrentTime();
cv::Mat angleImg;
cv::resize(partImgs[i], angleImg, cv::Size(dstWidth, dstHeight));
- //auto angleImg = adjustTargetImg(partImgs[i], dstWidth, dstHeight);
Angle angle = getAngle(angleImg);
double endAngle = getCurrentTime();
angle.time = endAngle - startAngle;
diff --git a/cpp/BaiPiaoOcrOnnx/src/CrnnNet.cpp b/cpp/BaiPiaoOcrOnnx/src/CrnnNet.cpp
index 4e2466d..c9040e9 100755
--- a/cpp/BaiPiaoOcrOnnx/src/CrnnNet.cpp
+++ b/cpp/BaiPiaoOcrOnnx/src/CrnnNet.cpp
@@ -60,8 +60,7 @@ void CrnnNet::initModel(const std::string &pathStr, const std::string &keysPath)
if (keys.size() != 6623) {
fprintf(stderr, "missing keys\n");
}
- keys.insert(keys.begin(),
- "#"); // blank char for ctc
+ keys.insert(keys.begin(),"#");
keys.emplace_back(" ");
printf("total keys size(%lu)\n", keys.size());
}
@@ -84,7 +83,7 @@ TextLine CrnnNet::scoreToTextLine(const std::vector<float> &outputData, int h, i
maxValue = float(*std::max_element(&outputData[i * w], &outputData[(i + 1) * w]));
if (maxIndex > 0 && maxIndex < keySize && (!(i > 0 && maxIndex == lastIndex))) {
- scores.push_back(maxValue);
+ scores.emplace_back(maxValue);
strRes.append(keys[maxIndex]);
}
lastIndex = maxIndex;
diff --git a/cpp/BaiPiaoOcrOnnx/src/DbNet.cpp b/cpp/BaiPiaoOcrOnnx/src/DbNet.cpp
index 10887d8..8aa9af1 100755
--- a/cpp/BaiPiaoOcrOnnx/src/DbNet.cpp
+++ b/cpp/BaiPiaoOcrOnnx/src/DbNet.cpp
@@ -1,6 +1,5 @@
#include "DbNet.h"
#include "OcrUtils.h"
-#include "clipper.hpp"
DbNet::DbNet() {}
@@ -105,7 +104,6 @@ std::vector<TextBox> findRsBoxes(const cv::Mat &predMat, const cv::Mat &dilateMa
return rsBoxes;
}
-
std::vector<TextBox>
DbNet::getTextBoxes(cv::Mat &src, ScaleParam &s, float boxScoreThresh, float boxThresh, float unClipRatio) {
cv::Mat srcResize;
diff --git a/cpp/BaiPiaoOcrOnnx/src/OcrLiteJni.cpp b/cpp/BaiPiaoOcrOnnx/src/OcrLiteJni.cpp
index fbff316..a9632fd 100755
--- a/cpp/BaiPiaoOcrOnnx/src/OcrLiteJni.cpp
+++ b/cpp/BaiPiaoOcrOnnx/src/OcrLiteJni.cpp
@@ -4,6 +4,7 @@
#include <jni.h>
#include "OcrLite.h"
#include "OcrResultUtils.h"
+#include "OcrUtils.h"
static OcrLite *ocrLite;
@@ -80,10 +81,10 @@ Java_com_benjaminwan_ocrlibrary_OcrEngine_initLogger(JNIEnv *env, jobject thiz,
extern "C" JNIEXPORT void JNICALL
Java_com_benjaminwan_ocrlibrary_OcrEngine_enableResultText(JNIEnv *env, jobject thiz, jstring input) {
- std::string argImgPath = jstringToChar(env, input);
- std::string imgPath = argImgPath.substr(0, argImgPath.find_last_of('/') + 1);
- std::string imgName = argImgPath.substr(argImgPath.find_last_of('/') + 1);
- ocrLite->enableResultTxt(imgPath.c_str(), imgName.c_str());
+ std::string imgPath = jstringToChar(env, input);
+ std::string imgDir = imgPath.substr(0, imgPath.find_last_of('/') + 1);
+ std::string imgName = imgPath.substr(imgPath.find_last_of('/') + 1);
+ ocrLite->enableResultTxt(imgDir.c_str(), imgName.c_str());
}
extern "C" JNIEXPORT jboolean JNICALL
@@ -94,26 +95,53 @@ Java_com_benjaminwan_ocrlibrary_OcrEngine_initModels(JNIEnv *env, jobject thiz,
std::string clsName = jstringToChar(env, cls);
std::string recName = jstringToChar(env, rec);
std::string keysName = jstringToChar(env, keys);
- std::string detPath = modelsDir + "/" + detName;
- std::string clsPath = modelsDir + "/" + clsName;
- std::string recPath = modelsDir + "/" + recName;
+ std::string modelDetPath = modelsDir + "/" + detName;
+ std::string modelClsPath = modelsDir + "/" + clsName;
+ std::string modelRecPath = modelsDir + "/" + recName;
std::string keysPath = modelsDir + "/" + keysName;
printf("modelsDir=%s\ndet=%s\ncls=%s\nrec=%s\nkeys=%s\n", modelsDir.c_str(), detName.c_str(), clsName.c_str(),
recName.c_str(), keysName.c_str());
- ocrLite->initModels(detPath, clsPath, recPath, keysPath);
+ bool hasModelDetFile = isFileExists(modelDetPath);
+ if (!hasModelDetFile) {
+ fprintf(stderr, "Model det file not found: %s\n", modelDetPath.c_str());
+ return false;
+ }
+ bool hasModelClsFile = isFileExists(modelClsPath);
+ if (!hasModelClsFile) {
+ fprintf(stderr, "Model cls file not found: %s\n", modelClsPath.c_str());
+ return false;
+ }
+ bool hasModelRecFile = isFileExists(modelRecPath);
+ if (!hasModelRecFile) {
+ fprintf(stderr, "Model rec file not found: %s\n", modelRecPath.c_str());
+ return false;
+ }
+ bool hasKeysFile = isFileExists(keysPath);
+ if (!hasKeysFile) {
+ fprintf(stderr, "keys file not found: %s\n", keysPath.c_str());
+ return false;
+ }
+ ocrLite->initModels(modelDetPath, modelClsPath, modelRecPath, keysPath);
return true;
}
extern "C" JNIEXPORT jobject JNICALL
-Java_com_benjaminwan_ocrlibrary_OcrEngine_detect(JNIEnv *env, jobject thiz, jstring input, jint padding, jint maxSideLen,
+Java_com_benjaminwan_ocrlibrary_OcrEngine_detect(JNIEnv *env, jobject thiz, jstring input, jint padding,
+ jint maxSideLen,
jfloat boxScoreThresh, jfloat boxThresh, jfloat unClipRatio,
jboolean doAngle, jboolean mostAngle
) {
- std::string argImgPath = jstringToChar(env, input);
- std::string imgPath = argImgPath.substr(0, argImgPath.find_last_of('/') + 1);
- std::string imgName = argImgPath.substr(argImgPath.find_last_of('/') + 1);
- printf("imgPath=%s, imgName=%s\n", imgPath.c_str(), imgName.c_str());
- OcrResult result = ocrLite->detect(imgPath.c_str(), imgName.c_str(), padding, maxSideLen,
+ std::string imgPath = jstringToChar(env, input);
+ bool hasTargetImgFile = isFileExists(imgPath);
+ if (!hasTargetImgFile) {
+ fprintf(stderr, "Target image not found: %s\n", imgPath.c_str());
+ OcrResult result{};
+ return OcrResultUtils(env, result).getJObject();
+ }
+ std::string imgDir = imgPath.substr(0, imgPath.find_last_of('/') + 1);
+ std::string imgName = imgPath.substr(imgPath.find_last_of('/') + 1);
+ printf("imgDir=%s, imgName=%s\n", imgDir.c_str(), imgName.c_str());
+ OcrResult result = ocrLite->detect(imgDir.c_str(), imgName.c_str(), padding, maxSideLen,
boxScoreThresh, boxThresh, unClipRatio, doAngle, mostAngle);
return OcrResultUtils(env, result).getJObject();
}
diff --git a/cpp/BaiPiaoOcrOnnx/src/OcrUtils.cpp b/cpp/BaiPiaoOcrOnnx/src/OcrUtils.cpp
index 6ea95fd..f459cdd 100755
--- a/cpp/BaiPiaoOcrOnnx/src/OcrUtils.cpp
+++ b/cpp/BaiPiaoOcrOnnx/src/OcrUtils.cpp
@@ -180,7 +180,7 @@ cv::Mat adjustTargetImg(cv::Mat &src, int dstWidth, int dstHeight) {
return srcFit;
}
-bool cvPointCompare(cv::Point a, cv::Point b) {
+bool cvPointCompare(const cv::Point &a, const cv::Point &b) {
return a.x < b.x;
}
diff --git a/cpp/BaiPiaoOcrOnnx/src/main.cpp b/cpp/BaiPiaoOcrOnnx/src/main.cpp
index 0ea3f26..db42d20 100644
--- a/cpp/BaiPiaoOcrOnnx/src/main.cpp
+++ b/cpp/BaiPiaoOcrOnnx/src/main.cpp
@@ -1,9 +1,11 @@
+#ifndef __JNI__
#include <omp.h>
#include <cstdio>
#include <string>
#include "main.h"
#include "version.h"
#include "OcrLite.h"
+#include "OcrUtils.h"
void printHelp(FILE *out, char *argv0) {
fprintf(out, " ------- Usage -------\n");
@@ -24,10 +26,8 @@ int main(int argc, char **argv) {
printHelp(stderr, argv[0]);
return -1;
}
- std::string modelsDir = "../models";
- std::string modelDetPath, modelClsPath, modelRecPath, keysPath;
- std::string argImgPath = "../../test_imgs/1.jpg";
- std::string imgPath, imgName;
+ std::string modelsDir, modelDetPath, modelClsPath, modelRecPath, keysPath;
+ std::string imgPath, imgDir, imgName;
int numThread = 4;
int padding = 0;
int maxSideLen = 1024;
@@ -36,8 +36,8 @@ int main(int argc, char **argv) {
float unClipRatio = 2.0f;
bool doAngle = true;
int flagDoAngle = 1;
- bool mostAngle = false;
- int flagMostAngle = 0;
+ bool mostAngle = true;
+ int flagMostAngle = 1;
int opt;
int optionIndex = 0;
@@ -65,10 +65,10 @@ int main(int argc, char **argv) {
printf("keys path=%s\n", keysPath.c_str());
break;
case 'i':
- argImgPath.assign(optarg);
- imgPath.assign(argImgPath.substr(0, argImgPath.find_last_of('/') + 1));
- imgName.assign(argImgPath.substr(argImgPath.find_last_of('/') + 1));
- printf("imgPath=%s, imgName=%s\n", imgPath.c_str(), imgName.c_str());
+ imgPath.assign(optarg);
+ imgDir.assign(imgPath.substr(0, imgPath.find_last_of('/') + 1));
+ imgName.assign(imgPath.substr(imgPath.find_last_of('/') + 1));
+ printf("imgDir=%s, imgName=%s\n", imgDir.c_str(), imgName.c_str());
break;
case 't':
numThread = (int) strtol(optarg, NULL, 10);
@@ -122,6 +122,31 @@ int main(int argc, char **argv) {
printf("other option %c :%s\n", opt, optarg);
}
}
+ bool hasTargetImgFile = isFileExists(imgPath);
+ if (!hasTargetImgFile) {
+ fprintf(stderr, "Target image not found: %s\n", imgPath.c_str());
+ return -1;
+ }
+ bool hasModelDetFile = isFileExists(modelDetPath);
+ if (!hasModelDetFile) {
+ fprintf(stderr, "Model det file not found: %s\n", modelDetPath.c_str());
+ return -1;
+ }
+ bool hasModelClsFile = isFileExists(modelClsPath);
+ if (!hasModelClsFile) {
+ fprintf(stderr, "Model cls file not found: %s\n", modelClsPath.c_str());
+ return -1;
+ }
+ bool hasModelRecFile = isFileExists(modelRecPath);
+ if (!hasModelRecFile) {
+ fprintf(stderr, "Model rec file not found: %s\n", modelRecPath.c_str());
+ return -1;
+ }
+ bool hasKeysFile = isFileExists(keysPath);
+ if (!hasKeysFile) {
+ fprintf(stderr, "keys file not found: %s\n", keysPath.c_str());
+ return -1;
+ }
omp_set_num_threads(numThread);
OcrLite ocrLite;
ocrLite.setNumThread(numThread);
@@ -130,7 +155,7 @@ int main(int argc, char **argv) {
false,//isOutputPartImg
true);//isOutputResultImg
- ocrLite.enableResultTxt(imgPath.c_str(), imgName.c_str());
+ ocrLite.enableResultTxt(imgDir.c_str(), imgName.c_str());
ocrLite.Logger("=====Input Params=====\n");
ocrLite.Logger(
"numThread(%d),padding(%d),maxSideLen(%d),boxScoreThresh(%f),boxThresh(%f),unClipRatio(%f),doAngle(%d),mostAngle(%d)\n",
@@ -138,8 +163,10 @@ int main(int argc, char **argv) {
ocrLite.initModels(modelDetPath, modelClsPath, modelRecPath, keysPath);
- OcrResult result = ocrLite.detect(imgPath.c_str(), imgName.c_str(), padding, maxSideLen,
+ OcrResult result = ocrLite.detect(imgDir.c_str(), imgName.c_str(), padding, maxSideLen,
boxScoreThresh, boxThresh, unClipRatio, doAngle, mostAngle);
ocrLite.Logger("%s\n", result.strRes.c_str());
return 0;
}
+
+#endif
\ No newline at end of file
diff --git a/cpp/BaiPiaoOcrOnnx/valgrind-memcheck.sh b/cpp/BaiPiaoOcrOnnx/valgrind-memcheck.sh
index 4f90185..ad0325c 100755
--- a/cpp/BaiPiaoOcrOnnx/valgrind-memcheck.sh
+++ b/cpp/BaiPiaoOcrOnnx/valgrind-memcheck.sh
@@ -12,6 +12,12 @@ NUM_THREADS=1
set OMP_NUM_THREADS=$NUM_THREADS
+TARGET_IMG=../../images/1.jpg
+if [ ! -f "$TARGET_IMG" ]; then
+echo "找不到待识别的目标图片:${TARGET_IMG},请打开本文件并编辑TARGET_IMG"
+exit
+fi
+
##### run test on MacOS or Linux
valgrind --tool=memcheck --leak-check=full --leak-resolution=med --track-origins=yes --vgdb=no --log-file=valgrind-memcheck.txt \
./build/BaiPiaoOcrOnnx --models models \
@@ -19,7 +25,7 @@ valgrind --tool=memcheck --leak-check=full --leak-resolution=med --track-origins
--cls ch_ppocr_mobile_v2.0_cls_infer.onnx \
--rec ch_ppocr_server_v2.0_rec_infer.onnx \
--keys ppocr_keys_v1.txt \
---image ../../test_imgs/1.jpg \
+--image $TARGET_IMG \
--numThread $NUM_THREADS \
--padding 0 \
--maxSideLen 1024 \
@@ -27,4 +33,4 @@ valgrind --tool=memcheck --leak-check=full --leak-resolution=med --track-origins
--boxThresh 0.3 \
--unClipRatio 1.5 \
--doAngle 1 \
---mostAngle 0
+--mostAngle 1