forked from ksasso1028/EasyOCR-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpenvinoExample.cpp
More file actions
52 lines (45 loc) · 1.9 KB
/
OpenvinoExample.cpp
File metadata and controls
52 lines (45 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include "OpenVINOModel.h"
#include "CRAFT.h"
#include "CRNN.h"
#include <opencv2/opencv.hpp>
#include <iostream>
int main()
{
CraftModel detection;
CRNNModel recognition;
std::string det = "CRAFT-detector.xml";
std::string rec = "recognition_model.xml";
std::string filePath = "test.jpg";
std::string device = "CPU";
auto check_det = detection.loadModel(det, device);
auto check_rec = recognition.loadModel(rec, device);
cv::Mat matInput = detection.loadMat(filePath, false, true).clone();
HeatMapRatio processed = detection.resizeAspect(matInput);
cv::Mat clone = processed.img.clone();
cv::Mat grey = processed.img.clone();
grey.convertTo(grey, CV_8UC1);
cv::cvtColor(grey, grey, cv::COLOR_BGR2GRAY);
clone.convertTo(clone, CV_8UC3);
ov::Tensor input = detection.preProcess(processed.img.clone());
auto ss = std::chrono::high_resolution_clock::now();
std::vector<BoundingBox> dets = detection.runDetector(input, true);
std::vector<TextResult> results = recognition.recognize(dets, grey);
auto ee = std::chrono::high_resolution_clock::now();
auto difff = ee - ss;
int count = 0;
for (auto x : dets)
{
rectangle(clone, x.topLeft, x.bottomRight, cv::Scalar(0, 255, 0));
putText(clone, std::to_string(count), (x.bottomRight + x.topLeft) / 2, cv::FONT_HERSHEY_COMPLEX, .6, cv::Scalar(100, 0, 255));
count++;
}
for (auto& result : results)
{
std::cout << "LOCATION: " << result.coords.topLeft << " " << result.coords.bottomRight << std::endl;
std::cout << "TEXT: " << result.text << std::endl;
std::cout << "CONFIDENCE " << result.confidence << std::endl;
std::cout << "################################################" << std::endl;
}
std::cout << "TOTAL INFERENCE TIME " << std::chrono::duration <double, std::milli>(difff).count() << " ms" << std::endl;
return 0;
}