Win10, VS2017, MFC C++ application, Tesseract 4.1.1

I started *TessBaseAPI::ProcessPage* call, and I realized I couldn't stop 
it. I noticed the prototype of *TessBaseAPI::ProcessPages*, if the int 
timeout_millisec parameter is greater than 0, the library uses internally a 
*ETEXT_DESC* monitor:

// *from TessBaseAPI source code:*

bool TessBaseAPI::ProcessPage(Pix* pix, int page_index, const char* 
filename,
                              const char* retry_config, int 
timeout_millisec,
                              TessResultRenderer* renderer) {
....
    PageIterator* it = AnalyseLayout();

    if (it == nullptr) {
      failed = true;
    } else {
      delete it;
    }
  } else if (tesseract_->tessedit_pageseg_mode == PSM_OSD_ONLY) {
    failed = FindLines() != 0;
  } else if (timeout_millisec > 0) {
    // Running with a timeout.
    ETEXT_DESC monitor;
    monitor.cancel = nullptr;
    monitor.cancel_this = nullptr;
    monitor.set_deadline_msecs(timeout_millisec);

as you see, if *timeout_millisec* is greater than 0, some monitor is set 
up, however, not to stopping the process on demand, but for timout.

My question is: can be stopped *TessBaseAPI::ProcessPages* in a way, maybe 
using *ETEXT_DESC* ?

I have tried this (*ReadImageThread* is used as multi-thread, not as single 
thread):

void CMyDocEx::ReadImageThread(const CString& sSrcFile)
{
    do
    {
        std::shared_ptr<tesseract::TessBaseAPI> api = 
std::make_shared<tesseract::TessBaseAPI>();
        if (api->Init(CStringA(GetAppPathTemp()), "eng"))
        {
            break;
        }

        api->Recognize(&m_monitor);

        std::shared_ptr<tesseract::TessPDFRenderer> renderer =
                std::make_shared<tesseract::TessPDFRenderer>(
                CStringA(GetFileName(sSrcFile)), api->GetDatapath(), false);

        if (! api->ProcessPages(CStringA(sSrcFile), nullptr, 0, 
renderer.get()))
        {
            break;
        }
        api->End();
    } while (FALSE);
}

where *m_monitor* is defined in my *CMyDocEx* header:

class CMyDocEx : public CDocument
{
....
protected:
    static bool cancel(void* cancel_this, int words)
    {
        return m_bCancelFlag;
    }
....
protected:
    ETEXT_DESC m_monitor;
    static bool m_bCancelFlag;
....
}

and implementation file (*cpp*):

bool CMyDocEx::m_bCancelFlag = false;

CMyDocEx::CMyDocEx()
{
    // TODO: add one-time construction code here

    m_monitor.cancel = &CMyDocEx::cancel;
    m_monitor.cancel_this = 
reinterpret_cast<void*>(CMyDocEx::m_bCancelFlag);
}

and when I put *m_bCancelFlag* to true, seems to happen nothing ...

-- 
You received this message because you are subscribed to the Google Groups 
"tesseract-ocr" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tesseract-ocr/e5d8f921-d528-486e-8a67-f3e9110b03d6n%40googlegroups.com.

Reply via email to