Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use c++ 17 lambda function for progress_callback2 #4159

Open
farfromrefug opened this issue Nov 8, 2023 · 2 comments
Open

use c++ 17 lambda function for progress_callback2 #4159

farfromrefug opened this issue Nov 8, 2023 · 2 comments

Comments

@farfromrefug
Copy link

Current Behavior

progress_callback2 is a function pointer

In my use case i need to use a c++ lambda function with capture as progress_callback2. Something like this:

int16_t lastProgress;
*monitor = tesseract::ETEXT_DESC();
monitor->progress_callback2 = [&] (tesseract::ETEXT_DESC* monitor, int left, int right, int top, int bottom) -> bool {
    int16_t progress = monitor->progress;
    if (progress > lastProgress) {
        lastProgress = progress;
    }
    progressLambda.value()(lastProgress);
    return true;
};

progressLambda is another lambda function which i pass a std::optional<std::function>

But this wont work because of the capture [&]. It is apparently not possible to cast it to function pointer

Expected Behavior

Being able to pass the lambda function

Suggested Fix

I managed to fix it replacing the type of PROGRESS_FUNC2 to:

using PROGRESS_FUNC2 = std::function<bool(ETEXT_DESC *, int, int, int, int)>;

I can make a PR for this but i want to be sure first that it would be something you would access.
I think it would be a breaking change because pointer function cannot be casted to std::function.

tesseract -v

No response

Operating System

No response

Other Operating System

No response

uname -a

No response

Compiler

No response

CPU

No response

Virtualization / Containers

No response

Other Information

No response

@zdenop
Copy link
Contributor

zdenop commented Jan 13, 2024

The best way it create PR, it can be easily tested.

@danpla
Copy link
Contributor

danpla commented Jan 13, 2024

As a workaround, you can put your data in a local struct and access it via ETEXT_DESC::cancel_this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants