|
@@ -264,13 +264,33 @@ int handwriting(string strImage, std::string &json_result, const std::string &ac
|
|
|
return is_success;
|
|
|
}
|
|
|
|
|
|
-int IdentifyCallback(result::spinfo& pinfo, void* param)
|
|
|
+void ParseJson(std::string& strJson, vector<std::tuple<cv::Rect, std::string>>& vec)
|
|
|
{
|
|
|
- string strToken = UnicodeToGB2312(CConfig::Instance()->m_strToken);
|
|
|
- string strResult;
|
|
|
- string strEncode = GetImageEncodeString("d:\\202210122100_0001.jpg");
|
|
|
- handwriting(strEncode, strResult, strToken);
|
|
|
+ Json::Features features;
|
|
|
+ Json::Reader reader(features);
|
|
|
+ Json::Value root;
|
|
|
+ if (!reader.parse(strJson, root))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ Json::Value words_result = root["words_result"];
|
|
|
+ if (!words_result.isArray())
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ for (int i = 0; i < words_result.size(); i++)
|
|
|
+ {
|
|
|
+ Json::Value row = words_result[i];
|
|
|
+ Json::Value location = row["location"];
|
|
|
+ cv::Rect rc = cv::Rect(location["left"].asInt(), location["top"].asInt(), location["width"].asInt(), location["height"].asInt());
|
|
|
+ vec.push_back(make_tuple(rc, row["words"].asString()));
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+int IdentifyCallback(result::spinfo& pinfo, void* param)
|
|
|
+{
|
|
|
CMFCApplication1Dlg* pWnd = (CMFCApplication1Dlg*)theApp.m_pMainWnd;
|
|
|
if (pinfo.choiceRes.size() < 3 || pinfo.vecUrlAPath.size() == 0)
|
|
|
{
|
|
@@ -295,12 +315,20 @@ int IdentifyCallback(result::spinfo& pinfo, void* param)
|
|
|
number += pow(2, length - 1 - i);
|
|
|
}
|
|
|
|
|
|
+ string strToken = CT2A(CConfig::Instance()->m_strToken);
|
|
|
+ string strResult;
|
|
|
+ string strEncode = GetImageEncodeString(pinfo.vecUrlAPath[0]);
|
|
|
+ handwriting(strEncode, strResult, strToken);
|
|
|
+
|
|
|
+ vector<std::tuple<cv::Rect, std::string>> vecTranslate;
|
|
|
+ ParseJson(strResult, vecTranslate);
|
|
|
+
|
|
|
std::string strJsonDir = CT2A(CConfig::Instance()->m_strMode);
|
|
|
strJsonDir.append("/");
|
|
|
strJsonDir.append(std::to_string(number));
|
|
|
strJsonDir.append(".json");
|
|
|
std::string strSaveDir = CT2A(CConfig::Instance()->m_strCut);
|
|
|
- cutPaper(number, strJsonDir, pinfo.vecUrlAPath[0], strSaveDir);
|
|
|
+ cutPaper(number, strJsonDir, pinfo.vecUrlAPath[0], strSaveDir, vecTranslate);
|
|
|
g_scanCount++;
|
|
|
pWnd->PostMessage(WM_PROCESS, NULL, NULL);
|
|
|
pWnd->FormatScanMsg("生成切割图像:%s", std::to_string(number).c_str());
|
|
@@ -813,6 +841,20 @@ void CMFCApplication1Dlg::OnBnClickedBtnScan()
|
|
|
::CreateDirectory(strAbnormal, 0);
|
|
|
}
|
|
|
|
|
|
+ CString strNormalSmall(m_strCutPath);
|
|
|
+ strNormalSmall.Append(L"/normal_small");
|
|
|
+ if (!PathIsDirectory(strNormalSmall))
|
|
|
+ {
|
|
|
+ ::CreateDirectory(strNormalSmall, 0);
|
|
|
+ }
|
|
|
+
|
|
|
+ CString strAbnormalSmall(m_strCutPath);
|
|
|
+ strAbnormalSmall.Append(L"/abnormal_small");
|
|
|
+ if (!PathIsDirectory(strAbnormalSmall))
|
|
|
+ {
|
|
|
+ ::CreateDirectory(strAbnormalSmall, 0);
|
|
|
+ }
|
|
|
+
|
|
|
SAFETY_EXIT_THREAD(_threadScan, 100);
|
|
|
_threadScan = CreateThread(NULL, 0, ScanThread, NULL, 0, NULL);
|
|
|
}
|