Browse Source

Merge branch 'translation' of http://gitz.zhixinhuixue.net:18880/zxhx-client-tool/pdfproject into translation

# Conflicts:
#	MFCApplication1/Config.cpp
#	MFCApplication1/Config.h
#	MFCApplication1/MFCApplication1Dlg.cpp
maoyehu 2 years ago
parent
commit
4d8502a7cc

+ 1 - 1
MFCApplication1/BaseUtility.cpp

@@ -1217,7 +1217,7 @@ string GetImageEncodeString(string strPath)
 	string strTemp = "data:image/jpeg;base64,";
 	strTemp.append(strImg);
 	//´òÓ¡img¿´Ò»ÏÂ
-	string strEncode = UrlEncode(strTemp);
+	//string strEncode = UrlEncode(strTemp);
 
 	//ɾ³ýbuffer
 	delete[]buffer;

+ 45 - 1
MFCApplication1/CvxText.cpp

@@ -582,6 +582,25 @@ int dataCollectionPaper(int cols, int index, int fontSize, int lineGrayPix, bool
 	return 0;
 }
 
+// rect_label : 模板的切割区域  rect_ocr :检测到的手写区域
+double math_iou(cv::Rect rect_label, cv::Rect rect_ocr)
+{
+	int endx = max(rect_label.x + rect_label.width, rect_ocr.x + rect_ocr.width);
+	int startx = min(rect_label.x, rect_ocr.x);
+	int width = rect_label.width + rect_ocr.width - (endx - startx);
+
+	int endy = max(rect_label.y + rect_label.height, rect_ocr.y + rect_ocr.height);
+	int	starty = min(rect_label.y, rect_ocr.y);
+	int height = rect_label.height + rect_ocr.height - (endy - starty);
+
+	double area = 0.0, iou = 0.0;
+	if (width <= 0 || height <= 0)
+		return 0.0;
+	area = width * height*1.0;
+	iou = area / double(rect_ocr.area());
+	return iou;
+}
+
 int get_gray_num(cv::Mat & img, cv::Rect & box, int &meanGray, int threshold) {
 	uchar * ptr;
 	int count = 0;
@@ -629,7 +648,7 @@ bool analysis_ttbox_mark(cv::Mat & imgSrc, cv::Rect & rc) {
 	return false;
 }
 
-int cutPaper(int pageNum, std::string strJsonPath, std::string strPaperPath, std::string strSavePath)
+int cutPaper(int pageNum, std::string strJsonPath, std::string strPaperPath, std::string strSavePath, vector<std::tuple<cv::Rect, std::string>>& vecTranslate)
 {
 	ifstream in(strJsonPath, ios::binary);
 	if (!in.is_open())
@@ -718,6 +737,31 @@ int cutPaper(int pageNum, std::string strJsonPath, std::string strPaperPath, std
 
 		cv::Mat cut = src(rc_ansInfo);
 		cv::imwrite(szJpgPath, cut);
+
+		for (auto& iter : vecTranslate)
+		{
+			cv::Rect rcOcr = std::get<0>(iter);
+			std::string words = std::get<1>(iter);
+			if (math_iou(rc_ansInfo, rcOcr) > 0.5)
+			{
+				char szOcrJpgPath[MAX_PATH] = { 0 };
+				char szOcrJpgText[MAX_PATH] = { 0 };
+				sprintf(szOcrJpgPath, "%s\\%s\\%d_%s_%ld_%d_%d_%d_%d.jpg", strSavePath.c_str(), ret ? "abnormal_small" : "normal_small", pageNum, id.c_str(), dwCount,
+					rcOcr.x - rc_ansInfo.x, rcOcr.y - rc_ansInfo.y, rcOcr.width, rcOcr.height);
+				sprintf(szOcrJpgText, "%s\\%s\\%d_%s_%ld_%d_%d_%d_%d.txt", strSavePath.c_str(), ret ? "abnormal_small" : "normal_small", pageNum, id.c_str(), dwCount,
+					rcOcr.x - rc_ansInfo.x, rcOcr.y - rc_ansInfo.y, rcOcr.width, rcOcr.height);
+
+				CFile zip3;
+				zip3.Open(CA2T(szOcrJpgText), CFile::modeCreate | CFile::modeWrite);
+				zip3.Write((void*)words.c_str(), words.length());
+				zip3.Close();
+
+				cv::Mat cut = src(rcOcr);
+				cv::imwrite(szOcrJpgPath, cut);
+
+				break;
+			}
+		}
 	}
 
 	return 0;

+ 2 - 1
MFCApplication1/CvxText.h

@@ -57,10 +57,11 @@ int dataCollectionPaper(int cols, int index, int fontSize, int lineGrayPix, bool
 	*  @input    :  strJsonPath:	Ä£°åJson·¾¶
 	*  @input    :  strPaperPath:	´ðÌ⿨·¾¶
 	*  @input    :  strSavePath:	´æ´¢Â·¾¶
+	*  @input    :  vecTranslate:	°Ù¶Èʶ±ðºó·µ»ØµÄ
 	*  @return   :  > 0 ʧ°Ü
 	*  @author   :  qqm  2022/08/31 19:42
 *********************************************************/
-int cutPaper(int pageNum, std::string strJsonPath, std::string strPaperPath, std::string strSavePath);
+int cutPaper(int pageNum, std::string strJsonPath, std::string strPaperPath, std::string strSavePath, vector<std::tuple<cv::Rect, std::string>>& vecTranslate);
 
 
 int PareseModeJson(preinfo::templatesInfo&  temeplatInfo);

+ 43 - 1
MFCApplication1/MFCApplication1Dlg.cpp

@@ -264,6 +264,31 @@ int handwriting(string strImage, std::string &json_result, const std::string &ac
 	return is_success;
 }
 
+void ParseJson(std::string& strJson, vector<std::tuple<cv::Rect, std::string>>& vec)
+{
+	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;
@@ -295,12 +320,15 @@ int IdentifyCallback(result::spinfo& pinfo, void* param)
 	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);
 }