2024-07-13 21:55:16 +08:00
|
|
|
#include <stdafx.h>
|
|
|
|
#include <wechatocr.h>
|
2024-11-04 23:10:41 +08:00
|
|
|
#define DECLARE_API extern "C" __declspec(dllexport)
|
2024-07-13 21:55:16 +08:00
|
|
|
|
2024-11-04 23:10:41 +08:00
|
|
|
DECLARE_API void *wcocr_init(const wchar_t *wexe, const wchar_t *wwcdir)
|
2024-07-13 21:55:16 +08:00
|
|
|
{
|
|
|
|
auto obj = new CWeChatOCR(wexe, wwcdir);
|
|
|
|
if (obj->wait_connection(5000))
|
|
|
|
{
|
|
|
|
return obj;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
delete obj;
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-11-04 23:10:41 +08:00
|
|
|
DECLARE_API void wcocr_destroy(void *pobj)
|
2024-07-13 21:55:16 +08:00
|
|
|
{
|
|
|
|
if (!pobj)
|
|
|
|
return;
|
|
|
|
auto obj = reinterpret_cast<CWeChatOCR *>(pobj);
|
|
|
|
delete obj;
|
|
|
|
}
|
2024-11-04 23:10:41 +08:00
|
|
|
DECLARE_API bool wcocr_ocr(void *pobj, const char *u8path, void (*cb)(int, int, int, int, LPCSTR))
|
2024-07-13 21:55:16 +08:00
|
|
|
{
|
|
|
|
if (!pobj)
|
2024-07-14 15:09:37 +08:00
|
|
|
return false;
|
2024-07-13 21:55:16 +08:00
|
|
|
auto obj = reinterpret_cast<CWeChatOCR *>(pobj);
|
|
|
|
CWeChatOCR::result_t res;
|
2024-07-14 15:09:37 +08:00
|
|
|
if (!obj->doOCR(u8path, &res))
|
|
|
|
return false;
|
2024-07-13 21:55:16 +08:00
|
|
|
for (auto &blk : res.ocr_response)
|
|
|
|
{
|
2024-07-14 15:09:37 +08:00
|
|
|
cb(blk.left, blk.top, blk.right, blk.bottom, blk.text.c_str());
|
2024-07-13 21:55:16 +08:00
|
|
|
}
|
2024-07-14 15:09:37 +08:00
|
|
|
return true;
|
2024-07-13 21:55:16 +08:00
|
|
|
}
|