-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOCRModule.cpp
More file actions
56 lines (51 loc) · 2.38 KB
/
Copy pathOCRModule.cpp
File metadata and controls
56 lines (51 loc) · 2.38 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
52
53
54
55
56
/**
* @file
* Copyright (c) 2023 - Tidaly
* Authors:
* - Philippe CHEYPE <philippe.cheype@epitech.eu>
* - Quentin ROUVIER <quentin.rouvier@epitech.eu>
* NOTICE: All information contained herein is, and remains
* the property of Tidaly. Dissemination of this information
* or reproduction of this material is strictly forbidden
* unless prior written permission is obtained from Tidaly.
*/
#include "OCRModule.hpp"
template <>
std::shared_ptr<type::Image> const OCRModule<type::Image>::handle(
std::shared_ptr<type::Image> const &image,
type::ModuleBehaviour const behaviour
) {
static std::string const imagePath = "/tmp/tidaly-ocr-image.png";
static std::string const scriptPath = "/home/tidaly/ocr/App/Modules/OCRModule/PaddleOCR/PaddleOCR.py";
// static std::string const scriptPath = "/Users/phil/Tidaly/delivery/ImageProcessing/App/Modules/OCRModule/PaddleOCR/PaddleOCR.py";
// static std::string const failSafe = "/home/tidaly/delivery/tidaly-image-processing/bin/GCPOCR/GCPOCR.py";
try {
// if (!cv::imwrite(imagePath, image->image)) {
// throw ModuleError("Failed to write temporary image.");
// }
std::cerr << "[\033[0;33mINFO\033[0m] OCRModule: Calling PaddleOCR (running external python script: " << scriptPath << ")" << std::endl;
std::string output = this->_executor.executeScript(scriptPath, imagePath, image->lastValue);
// std::cerr << "[\033[0;33mINFO\033[0m] OCRModule: Finished PaddleOCR subprocess" << std::endl;
// if (output.length() == 0) {
// // call failsafe
// output = this->_executor.executeScript(failSafe, imagePath, image->lastValue);
// remove(imagePath.c_str());
// if (output.length() == 0) {
// throw std::invalid_argument("OCRModule: failed to recognize data, failsafe failed too");
// }
// }
remove(imagePath.c_str());
image->rawData = output;
image->status = type::Status::RECOGNIZED;
image->status_message = "OCRModule: recognized data: \"" + image->rawData + "\"";
} catch (std::exception const &e) {
image->status = type::Status::RECOGNIZE_ERROR;
image->status_message = e.what();
}
if (behaviour == type::ModuleBehaviour::NOTIFY) {
this->_mediator->notify(this, image);
} else {
return image;
}
return nullptr;
}