VLPR.cpp 1.4 KB
Newer Older
Your Name's avatar
Your Name committed
1
2
3
4
5
#include <VLPR.h>
#include <SimpleLog.h>

namespace migraphxSamples
{
liucong's avatar
liucong committed
6
VLPR::VLPR() {}
Your Name's avatar
Your Name committed
7

liucong's avatar
liucong committed
8
VLPR::~VLPR() { configurationFile.release(); }
Your Name's avatar
Your Name committed
9

liucong's avatar
liucong committed
10
11
ErrorCode VLPR::Initialize(InitializationParameterOfDB initParamOfDB,
                           InitializationParameterOfSVTR initParamOfSVTR)
Your Name's avatar
Your Name committed
12
13
14
{
    // 初始化DB
    initParamOfDB.configFilePath = CONFIG_FILE;
liucong's avatar
liucong committed
15
16
    ErrorCode errorCode          = db.Initialize(initParamOfDB);
    if(errorCode != SUCCESS)
Your Name's avatar
Your Name committed
17
18
19
20
21
22
23
24
    {
        LOG_ERROR(stdout, "fail to initialize db!\n");
        exit(-1);
    }
    LOG_INFO(stdout, "succeed to initialize db\n");

    // 初始化SVTR
    initParamOfSVTR.configFilePath = CONFIG_FILE;
liucong's avatar
liucong committed
25
26
    errorCode                      = svtr.Initialize(initParamOfSVTR);
    if(errorCode != SUCCESS)
Your Name's avatar
Your Name committed
27
28
29
30
31
    {
        LOG_ERROR(stdout, "fail to initialize svtr!\n");
        exit(-1);
    }
    LOG_INFO(stdout, "succeed to initialize svtr\n");
liucong's avatar
liucong committed
32
    return SUCCESS;
Your Name's avatar
Your Name committed
33
34
}

liucong's avatar
liucong committed
35
36
ErrorCode
VLPR::Infer(cv::Mat& img, std::vector<std::string>& recTexts, std::vector<float>& recTextScores)
Your Name's avatar
Your Name committed
37
38
{
    // DB推理
liucong's avatar
liucong committed
39
    db.Infer(img, imgLists);
Your Name's avatar
Your Name committed
40

liucong's avatar
liucong committed
41
    for(int i = 0; i < imgLists.size(); i++)
Your Name's avatar
Your Name committed
42
43
    {
        float maxWHRatio = float(imgLists[i].cols) / float(imgLists[i].rows);
liucong's avatar
liucong committed
44

Your Name's avatar
Your Name committed
45
46
47
48
49
50
51
52
53
        // SVTR推理
        svtr.Infer(imgLists[i], recText, recTextScore, maxWHRatio);
        recTexts.push_back(recText);
        recTextScores.push_back(recTextScore);
    }

    return SUCCESS;
}

liucong's avatar
liucong committed
54
} // namespace migraphxSamples