|
|
@@ -5,6 +5,8 @@
|
|
|
|
|
|
#include "../tool/CSerialPort.h"
|
|
|
|
|
|
+#include "../helper/CBitmapHelper.h"
|
|
|
+
|
|
|
void CValueWnd::Notify(TNotifyUI& msg)
|
|
|
{
|
|
|
if(msg.sType == _T("click"))
|
|
|
@@ -22,6 +24,9 @@ void CValueWnd::Init()
|
|
|
//初始化窗口位置
|
|
|
InitWndPos();
|
|
|
|
|
|
+ //抢焦点
|
|
|
+ std::thread(&CValueWnd::TopMostWnd, this).detach();
|
|
|
+
|
|
|
//添加托盘图标
|
|
|
AddTrayIcon();
|
|
|
|
|
|
@@ -44,6 +49,15 @@ void CValueWnd::Init()
|
|
|
pOcrWnd->Create(NULL, _T("智铺子收银插件OCR定位"), UI_WNDSTYLE_FRAME, WS_EX_TOOLWINDOW , 0, 0, 0, 0, NULL);
|
|
|
pOcrWnd->ShowWindow(false);
|
|
|
|
|
|
+ //OCR的数据初始化
|
|
|
+ if (m_tess.Init("./tessdata", "eng"))
|
|
|
+ {
|
|
|
+ std::cout << "OCRTesseract: Could not initialize tesseract." << std::endl;
|
|
|
+ }
|
|
|
+
|
|
|
+ m_tess.SetPageSegMode(tesseract::PageSegMode::PSM_SINGLE_LINE);
|
|
|
+ m_tess.SetVariable("save_best_choices", "T");
|
|
|
+
|
|
|
//再安装钩子
|
|
|
//BOOL ret = InstallHook();
|
|
|
|
|
|
@@ -51,6 +65,16 @@ void CValueWnd::Init()
|
|
|
RestartWatch();
|
|
|
}
|
|
|
|
|
|
+void CValueWnd::TopMostWnd()
|
|
|
+{
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ ::SetWindowPos(m_hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
|
|
|
+
|
|
|
+ Sleep(200);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void CValueWnd::RestartWatch()
|
|
|
{
|
|
|
std::thread(&CValueWnd::StartWatchWork, this).detach();
|
|
|
@@ -64,8 +88,8 @@ void CValueWnd::StartWatchWork()
|
|
|
//先暂停已有的监控
|
|
|
m_isWatchWork = false;
|
|
|
|
|
|
- //等待1秒,这1秒就是等已有的监控线程自动退出
|
|
|
- Sleep(1000);
|
|
|
+ //等待2秒,这2秒就是等已有的监控线程自动退出
|
|
|
+ Sleep(2000);
|
|
|
|
|
|
//然后开始工作
|
|
|
m_isWatchWork = true;
|
|
|
@@ -108,6 +132,10 @@ void CValueWnd::StartWatchWork()
|
|
|
|
|
|
std::thread(&CValueWnd::WatchWnd, this).detach();
|
|
|
}
|
|
|
+ else if (m_nWatchType == 4)
|
|
|
+ {
|
|
|
+ std::thread(&CValueWnd::StartOcrWork, this).detach();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/*
|
|
|
@@ -229,6 +257,58 @@ void CValueWnd::WatchWnd()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+void CValueWnd::StartOcrWork()
|
|
|
+{
|
|
|
+ int system_setting_jinezhuaqu_setting_ocr_left = atoi(CSetting::GetParam("system_setting_jinezhuaqu_setting_ocr_left").c_str());
|
|
|
+ int system_setting_jinezhuaqu_setting_ocr_top = atoi(CSetting::GetParam("system_setting_jinezhuaqu_setting_ocr_top").c_str());
|
|
|
+ int system_setting_jinezhuaqu_setting_ocr_right = atoi(CSetting::GetParam("system_setting_jinezhuaqu_setting_ocr_right").c_str());
|
|
|
+ int system_setting_jinezhuaqu_setting_ocr_bottom = atoi(CSetting::GetParam("system_setting_jinezhuaqu_setting_ocr_bottom").c_str());
|
|
|
+
|
|
|
+ //如果模式变了,或者参数变了,就退出(因为会重新启动一个新的监控)
|
|
|
+ while (m_nWatchType == 4 && m_isWatchWork)
|
|
|
+ {
|
|
|
+ RECT rect;
|
|
|
+ rect.left = system_setting_jinezhuaqu_setting_ocr_left;
|
|
|
+ rect.top = system_setting_jinezhuaqu_setting_ocr_top;
|
|
|
+ rect.right = system_setting_jinezhuaqu_setting_ocr_right;
|
|
|
+ rect.bottom = system_setting_jinezhuaqu_setting_ocr_bottom;
|
|
|
+
|
|
|
+ if (IsRectEmpty(&rect))
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ CBitmapHelper helper;
|
|
|
+
|
|
|
+ std::string ocr_result;
|
|
|
+ bool ret = helper.OcrRect(m_tess, &rect, ocr_result);
|
|
|
+
|
|
|
+ if (ret)
|
|
|
+ {
|
|
|
+ if (!atof(ocr_result.c_str()))
|
|
|
+ {
|
|
|
+ //识别结果不是有效的数字
|
|
|
+ CLabelUI* valueLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("value")));
|
|
|
+
|
|
|
+ valueLabel->SetText(L"0.00");
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ std::string format_value = CLewaimaiString::DoubleToString(atof(ocr_result.c_str()), 2);
|
|
|
+ std::wstring ws_ocr_result = CLewaimaiString::UTF8ToUnicode(format_value);
|
|
|
+
|
|
|
+ CLabelUI* valueLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("value")));
|
|
|
+
|
|
|
+ valueLabel->SetText(ws_ocr_result.c_str());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ Sleep(200);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
LRESULT CValueWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
{
|
|
|
LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
|
|
|
@@ -827,4 +907,9 @@ void CValueWnd::ConfirmOcrWnd(RECT rect)
|
|
|
|
|
|
//显示设置窗口
|
|
|
m_settingWnd->ShowWindow(true);
|
|
|
+}
|
|
|
+
|
|
|
+tesseract::TessBaseAPI& CValueWnd::GetTess()
|
|
|
+{
|
|
|
+ return m_tess;
|
|
|
}
|