|
@@ -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;
|