#ifndef __JNI__ #ifndef __CLIB__ #include #include "main.h" #include "version.h" #include "OcrLite.h" #include "OcrUtils.h" void printHelp(FILE *out, char *argv0) { fprintf(out, " ------- Usage -------\n"); fprintf(out, "%s %s", argv0, usageMsg); fprintf(out, " ------- Required Parameters -------\n"); fprintf(out, "%s", requiredMsg); fprintf(out, " ------- Optional Parameters -------\n"); fprintf(out, "%s", optionalMsg); fprintf(out, " ------- Other Parameters -------\n"); fprintf(out, "%s", otherMsg); fprintf(out, " ------- Examples -------\n"); fprintf(out, example1Msg, argv0); fprintf(out, example2Msg, argv0); } int main(int argc, char **argv) { if (argc <= -1) { printHelp(stderr, argv[0]); return -1; } std::string modelsDir = "../Resource/Models"; std::string modelDetPath= "../Resource/Models/ch_PP-OCRv3_det_infer.onnx"; std::string modelClsPath = "../Resource/Models/ch_ppocr_mobile_v2.0_cls_infer.onnx"; std::string modelRecPath = "../Resource/Models/ch_PP-OCRv3_rec_infer.onnx"; std::string keysPath = "../Resource/Models/ppocr_keys_v1.txt"; std::string imgPath, imgDir, imgName; imgPath = "../Resource/Images/"; imgDir = "../Resource/Images/"; imgName = "1.jpg"; int numThread = 4; int padding = 50; int maxSideLen = 1024; float boxScoreThresh = 0.5f; float boxThresh = 0.3f; float unClipRatio = 1.6f; bool doAngle = true; int flagDoAngle = 1; bool mostAngle = true; int flagMostAngle = 1; int flagGpu = -1; int opt; int optionIndex = 0; //判断路径配置是否存在 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; } OcrLite ocrLite; ocrLite.setNumThread(numThread); ocrLite.initLogger( true,//isOutputConsole false,//isOutputPartImg true);//isOutputResultImg ocrLite.enableResultTxt(imgDir.c_str(), imgName.c_str()); ocrLite.setGpuIndex(flagGpu); ocrLite.Logger("=====Input Params=====\n"); ocrLite.Logger( "numThread(%d),padding(%d),maxSideLen(%d),boxScoreThresh(%f),boxThresh(%f),unClipRatio(%f),doAngle(%d),mostAngle(%d),GPU(%d)\n", numThread, padding, maxSideLen, boxScoreThresh, boxThresh, unClipRatio, doAngle, mostAngle, flagGpu); ocrLite.initModels(modelDetPath, modelClsPath, modelRecPath, keysPath); 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 #endif