Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/paddleocr-ncnn/paddleocr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,14 @@ void PaddleOCRApp::resetNet()
needReset = false;
}

void PaddleOCRApp::clearInferenceAllocators()
{
detBlobAllocator.clear();
detWorkspaceAllocator.clear();
recBlobAllocator.clear();
recWorkspaceAllocator.clear();
}

void PaddleOCRApp::initNet()
{
if(currentPath.empty()) {
Expand Down Expand Up @@ -162,6 +170,8 @@ void PaddleOCRApp::initNet()

detNet = new ncnn::Net;
detNet->opt = option;
detNet->opt.blob_allocator = &detBlobAllocator;
detNet->opt.workspace_allocator = &detWorkspaceAllocator;
detNet->opt.num_threads = static_cast<int>(maxThreadsUsed);
detNet->load_param_bin((detModel + paramSuffix).c_str());
detNet->load_model((detModel + binSuffix).c_str());
Expand All @@ -173,6 +183,8 @@ void PaddleOCRApp::initNet()

recNet = new ncnn::Net;
recNet->opt = option;
recNet->opt.blob_allocator = &recBlobAllocator;
recNet->opt.workspace_allocator = &recWorkspaceAllocator;

//由于检测网络的速度足够快,因此GPU设备仅给识别网络使用以节省GPU初始化时间
if (!gpuCanUse.empty()) {
Expand Down Expand Up @@ -605,6 +617,7 @@ bool PaddleOCRApp::analyze()
allResult.clear();
boxesResult.clear();
needBreak = false;
clearInferenceAllocators();
return false;
} else {
//对识别结果进行最后清理,将未识别到文字的检测框排除掉
Expand All @@ -617,7 +630,9 @@ bool PaddleOCRApp::analyze()
}
}

return !textBoxes.empty();
const bool result = !textBoxes.empty();
clearInferenceAllocators();
return result;
}
}

Expand Down
6 changes: 6 additions & 0 deletions src/paddleocr-ncnn/paddleocr.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@

#include <opencv2/opencv.hpp>

#include <utility>

Check warning on line 31 in src/paddleocr-ncnn/paddleocr.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <utility> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <atomic>

Check warning on line 32 in src/paddleocr-ncnn/paddleocr.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <atomic> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <ncnn/allocator.h>

Check warning on line 33 in src/paddleocr-ncnn/paddleocr.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <ncnn/allocator.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

namespace ncnn {
class Net;
Expand Down Expand Up @@ -64,11 +65,16 @@
std::atomic_bool needBreak = false;
ncnn::Net *detNet = nullptr;
ncnn::Net *recNet = nullptr;
ncnn::PoolAllocator detBlobAllocator;
ncnn::PoolAllocator detWorkspaceAllocator;
ncnn::PoolAllocator recBlobAllocator;
ncnn::PoolAllocator recWorkspaceAllocator;
std::vector<std::string> keys;
PaddleOCR::PostProcessor postProcessor;
PaddleOCR::Utility utilityTool;
void resetNet(); //重置网络
void initNet(); //初始化网络
void clearInferenceAllocators();
std::vector<std::vector<std::vector<int>>> detect(const cv::Mat &src, float thresh, float boxThresh, float unclipRatio); //检测
std::pair<std::string, std::vector<int>> ctcDecode(const std::vector<float> &recNetOutputData, int h, int w); //CTC解码
void rec(const std::vector<cv::Mat> &detectImg); //识别
Expand Down
Loading