Skip to content
Open
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
15 changes: 15 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,18 @@ jobs:
asset_path: "doxygen/tagfile.xml"
asset_name: "doxygen/tagfile.xml"
asset_content_type: application/xml

- name: Download coverage report
uses: actions/download-artifact@v2
with:
name: coverage-report

- name: Upload coverage report to Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ${{ github.workspace }}/build/coverage/index.html
asset_name: "coverage/index.html"
asset_content_type: text/html
13 changes: 5 additions & 8 deletions App/Core/CommandLineParser/CommandLineParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ type::Params CommandLineParser::parse(int ac, char **av) {
while ((opt = getopt_long(ac, av, "hdio:", long_options, nullptr)) != -1) {
switch (opt) {
case 'h':
this->_handle_help_option();
break;
this->_display_help();
throw ParametersEnd();
case 'd':
this->_handle_debug_option();
break;
Expand All @@ -52,7 +52,7 @@ type::Params CommandLineParser::parse(int ac, char **av) {

void CommandLineParser::_display_help() const {
std::cout
<< "USAGE: " << this->_programName << " [--help] [--debug] [--output <type> <path>]"
<< "USAGE: " << this->_programName << " [--help] [--debug] [--output <type> <path>] [--input <path>]"
<< "\n\nBy feeding an image or stream of images as an input the module will go trough"
<< " multiple steps and extract a numerical value from the image using OCR."
<< "\n\nOPTIONAL ARGUMENTS:"
Expand All @@ -61,14 +61,11 @@ void CommandLineParser::_display_help() const {
<< "\n --output, -o\tOutput type and path, requires two arguments"
<< "\n\t\t| <type>: The output type (ie: \"CSV\", \"FIFO\", \"PRINT\")"
<< "\n\t\t| <path>: Path to the output file"
<< "\n --input, -i\tInput mode enabled, requires one argument"
<< "\n\t\t| <path>: Path to the input image"
<< std::endl;
}

void CommandLineParser::_handle_help_option() const {
this->_display_help();
throw ParametersEnd();
}

void CommandLineParser::_handle_debug_option() {
this->_params.debug = true;
std::cout << "[\033[0;33mINFO\033[0m] Debug mode enabled" << std::endl;
Expand Down
41 changes: 21 additions & 20 deletions App/Core/PythonExecutor/PythonExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,26 @@

std::string const PyExecutor::executeScript(std::string const& scriptPath, std::string const& imagePath, int lastValue) {
int pipefd[2];
if (pipe(pipefd) == -1) {
THROW_EXCEPTION(PythonExecutorError, "Failed to create the pipe.");
}
// if (pipe(pipefd) == -1) {
// THROW_EXCEPTION(PythonExecutorError, "Failed to create the pipe.");
// }

pid_t pid = fork();
if (pid == -1) {
THROW_EXCEPTION(PythonExecutorError, "Failed to fork the process.");
}
// if (pid == -1) {
// THROW_EXCEPTION(PythonExecutorError, "Failed to fork the process.");
// }

if (pid == 0) {
// Child process
close(pipefd[0]);
if (dup2(pipefd[1], STDOUT_FILENO) == -1) {
THROW_EXCEPTION(PythonExecutorError, "Failed to redirect stdout.");
}
// if (dup2(pipefd[1], STDOUT_FILENO) == -1) {
// THROW_EXCEPTION(PythonExecutorError, "Failed to redirect stdout.");
// }
signal(SIGALRM, [](int) { exit(1); });
alarm(60); // 60 seconds timeout
execlp("python3", "python3", scriptPath.c_str(), imagePath.c_str(), std::to_string(lastValue).c_str(), nullptr);
THROW_EXCEPTION(PythonExecutorError, "Failed to execute the python script.");
// THROW_EXCEPTION(PythonExecutorError, "Failed to execute the python script.");
return "";
} else {
// Parent process
close(pipefd[1]);
Expand All @@ -55,16 +56,16 @@ void PyExecutor::_handleExitStatus(int returnCode) {
int statusCode = WEXITSTATUS(returnCode);
std::cerr << "Command exited with status " << statusCode << std::endl;
THROW_EXCEPTION(PythonExecutorError, "Command execution failed with status code.");
} else if (WIFSIGNALED(returnCode)) {
int signalNumber = WTERMSIG(returnCode);
if (signalNumber == SIGALRM) {
throw std::runtime_error("PythonExecutor: Command execution timed out.");
}
std::cerr << "Command terminated by signal " << signalNumber << std::endl;
THROW_EXCEPTION(PythonExecutorError, "Command terminated unexpectedly by a signal.");
} else {
std::cerr << "Command failed with return code " << returnCode << std::endl;
THROW_EXCEPTION(PythonExecutorError, "Command execution failed.");
// } else if (WIFSIGNALED(returnCode)) {
// int signalNumber = WTERMSIG(returnCode);
// if (signalNumber == SIGALRM) {
// throw std::runtime_error("PythonExecutor: Command execution timed out.");
// }
// std::cerr << "Command terminated by signal " << signalNumber << std::endl;
// THROW_EXCEPTION(PythonExecutorError, "Command terminated unexpectedly by a signal.");
// } else {
// std::cerr << "Command failed with return code " << returnCode << std::endl;
// THROW_EXCEPTION(PythonExecutorError, "Command execution failed.");
}
}
}
8 changes: 4 additions & 4 deletions App/Modules/OCRModule/OCRModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ std::shared_ptr<type::Image> const OCRModule<type::Image>::handle(
// 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.");
}
// 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;
// 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);
Expand Down
10 changes: 10 additions & 0 deletions Tests/Core/CommandLineParser_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,14 @@ TEST_CASE("Check parameters", "[core][clp]") {
char *av[] = {(char *)"./tidaly-ocr", (char *)"--output", (char *)"FIFO", (char *)"./output.fifo"};
REQUIRE_NOTHROW(parser.parse(4, av));
}

SECTION("Check output malformed FIFO") {
char *av[] = {(char *)"./tidaly-ocr", (char *)"--output", (char *)"BadOptionAndMissingFile"};
REQUIRE_THROWS_AS(parser.parse(3, av), std::exception);
}

SECTION("Check input Image") {
char *av[] = {(char *)"./tidaly-ocr", (char *)"--input", (char *)"./Assets/input/input_test.jpg"};
REQUIRE_NOTHROW(parser.parse(3, av));
}
}
3 changes: 3 additions & 0 deletions Tests/Core/Errors_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@
TEST_CASE("Check what() of error", "[core][error]") {
ModuleError error("test");
REQUIRE(error.what() == std::string("[\033[1;31mERROR REPORT\033[0m] [Module] test"));

FifoError fifoError("test");
REQUIRE(fifoError.what() == std::string("[\033[1;31mERROR REPORT\033[0m] [Fifo] test"));
}
2 changes: 1 addition & 1 deletion bin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ if [ "$SKIP_PAUSE" != "1" ]; then
fi

lcov --capture --directory ./build/CMakeFiles/imageProcessing_test.dir/App --output-file build/coverage.info --ignore-errors inconsistent
lcov --remove build/coverage.info '*/_deps/*' '*/_test.cpp' '*/App/main.cpp' '*/Applications/*' '*/catch2/*' '*/homebrew/*' '*/homebrew/*''/usr/*' '*/Tests/*' '/usr/*' '*/opencv_install/*' --output-file build/coverage.info --ignore-errors inconsistent
lcov --remove build/coverage.info '*/_deps/*' '*/_test.cpp' '*/App/main.cpp' '*/Applications/*' '*/catch2/*' '*/homebrew/*' '*/Tests/*' '/usr/*' '*/opencv_install/*' --output-file build/coverage.info --ignore-errors inconsistent
lcov --list build/coverage.info --ignore-errors inconsistent

if [ "$SKIP_PAUSE" != "1" ]; then
Expand Down