41 lines
978 B
C++
Raw Normal View History

2024-07-13 21:55:16 +08:00
#include <stdafx.h>
#include <wechatocr.h>
#define DECLARE extern "C" __declspec(dllexport)
DECLARE void *wcocr_init(const wchar_t *wexe, const wchar_t *wwcdir)
{
auto obj = new CWeChatOCR(wexe, wwcdir);
if (obj->wait_connection(5000))
{
return obj;
}
else
{
delete obj;
return nullptr;
}
}
DECLARE void wcocr_destroy(void *pobj)
{
if (!pobj)
return;
auto obj = reinterpret_cast<CWeChatOCR *>(pobj);
delete obj;
}
2024-07-14 15:09:37 +08:00
DECLARE 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
std::vector<std::wstring> rets;
std::vector<int> xs, ys, xs2, ys2;
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
}