ソースを参照

【bug修复】(黄根)优化主观题和填空题的红笔判分识别逻辑 && 解决上传至后端数据库时中文乱码的问题
【工作量】8h
【评审人】

huanggen 2 年 前
コミット
02159a6cfa
2 ファイル変更24 行追加15 行削除
  1. 22 14
      Identifier/PageIdentify.cpp
  2. 2 1
      SmartEvaluationLogic/BatchInfo.cpp

+ 22 - 14
Identifier/PageIdentify.cpp

@@ -769,7 +769,7 @@ namespace OnLineCard{
 				cvReleaseStructuringElement(&element);
 			if (m_pTemplate->open_save_debug_img){
 				char szImageName[1024] = { 0 };
-				sprintf_s(szImageName, "%s\\image\\Debug\\find_dingweidian_top%d.jpg", g_appFilePathName.c_str(), dir);
+				sprintf_s(szImageName, "%sD:\\ImageDebug\\YWY\\find_dingweidian_top%d.jpg", g_appFilePathName.c_str(), dir);
 				cvSaveImage(szImageName, binary_img);
 			}
 			int contours = cvFindContours(binary_img, storage, &contour, sizeof(CvContour), CV_RETR_LIST, CV_CHAIN_APPROX_NONE, cvPoint(roi[dir].x - 5, roi[dir].y - 5));
@@ -2971,7 +2971,7 @@ namespace OnLineCard{
 									red_area = red_in_count[i]; red_area_index = i;
 								}
 							}
-							if (red_area_index >= (qs.scoreBox.bPoint ? 1 : 0)){
+							if (red_area_index >= (qs.scoreBox.bPoint ? 1 : 0) && red_area > 25){
 								score += (qs.scoreBox.limit - red_area_index + (qs.scoreBox.bPoint ? 1 : 0));
 							}
 						}
@@ -2995,7 +2995,7 @@ namespace OnLineCard{
 									red_area = red_in_count[i]; red_area_index = i;
 								}
 							}
-							if (red_area_index >= (qs.scoreBox.bPoint ? 1 : 0)){
+							if (red_area_index >= (qs.scoreBox.bPoint ? 1 : 0) && red_area > 25){
 								score += (9 - red_area_index + (qs.scoreBox.bPoint ? 1 : 0));
 							}
 						}
@@ -3083,9 +3083,10 @@ namespace OnLineCard{
 						float w = (rx - lx) / qs.count;
 						float h = (point[2]->y - point[0]->y)*pscale;
 						for (int j = 0; j<1; j++){
-							CvRect rect_detect = cvRect(qs.scoreBox.pos.x, qs.scoreBox.pos.y, qs.scoreBox.pos.w, qs.scoreBox.pos.h);
+							CvRect rect_detect = cvRect(qs.scoreBox.pos.x, qs.scoreBox.pos.y, qs.scoreBox.pos.w, qs.scoreBox.pos.h * 0.88);
 							int red_area = GetTianKongTiRedCount(dst, rect_detect, rect_detect, 1, 0);
-							if (red_area > 25){
+							//此处不知应该使用什么判定值作为是非判分的标准,暂时根据测试答题卡定此表达式的值
+							if (red_area > rect_detect.width + 10){
 								tiankongti_result_value[tiankong_count].isright = TRUE;
 								break;
 							}
@@ -3501,7 +3502,7 @@ namespace OnLineCard{
 		IplImage * red = cvCreateImage(cvSize(w, h), IPL_DEPTH_8U, 1);
 		cvSetImageROI(dst, rect_detect);
 #if GETREDBINARY_DEBUG
-		cvSaveImage("D:\\dst.png", dst);
+		cvSaveImage("D:\\ImageDebug\\\\dst.png", dst);
 #endif
 		cvCvtColor(dst, hsv, CV_BGR2HSV);
 		cvCvtColor(dst, gray, CV_BGR2GRAY);
@@ -3520,7 +3521,7 @@ namespace OnLineCard{
 		const int hsv_s_valve_1 = /*255 * 23 / 100*/43;
 		const int hsv_s_valve_2 = /*255 * 33 / 100*/255;
 		const int hsv_valve_high = 255 * (23 + 70) / 100;
-		const int hsv_valve_low = 255 * (13 + 60) / 100;
+		const int hsv_valve_low = 255 * (23 + 69) / 100;
 		for (int y = 0; y<h; y++)
 		{
 			unsigned char * hsv_row_first = (unsigned char *)(hsv->imageData + y*hsv->widthStep);
@@ -3531,7 +3532,7 @@ namespace OnLineCard{
 			for (int x = 0, hsv_offset = 0; x<w; x++, hsv_offset += 3)
 			{
 				if (HSV_VALUE_V >= hsv_v_valve && (HSV_VALUE_H >= hsv_h_min_valve || HSV_VALUE_H <= hsv_h_max_valve || HSV_VALUE_H <= hsv_h_max_valve2)){
-					red1_row_first[x] = (HSV_VALUE_S >= hsv_s_valve_1 && (HSV_VALUE_S + HSV_VALUE_V) >= hsv_valve_low) ? 255 : 0;
+					red1_row_first[x] = (HSV_VALUE_S >= hsv_s_valve_1 && (HSV_VALUE_S + HSV_VALUE_V) >= hsv_valve_low) ? /*255*/HSV_VALUE_S : 0;
 					red2_row_first[x] = (HSV_VALUE_S >= hsv_s_valve_2 && (HSV_VALUE_S + HSV_VALUE_V) >= hsv_valve_high) ? HSV_VALUE_S : 0;
 				}
 				else{
@@ -3552,10 +3553,13 @@ namespace OnLineCard{
 		cvSaveImage("D:\\red_high.png", red_high);
 #endif
 		int an = 1;
-		IplConvKernel * element = cvCreateStructuringElementEx(an * 2 + 1, an * 2 + 1, an, an, CV_SHAPE_RECT, 0);//创建结构元素   
+		IplConvKernel * element = cvCreateStructuringElementEx(an + 1, an + 1, an, an, CV_SHAPE_RECT, 0);//创建结构元素   
 		cvDilate(binary, binary, element, 2);//膨胀图像   
 		cvDilate(red_high, red_high, element, 2);//膨胀图像   
 		cvDilate(black, black_dilate, element, 2);//膨胀图像  
+#if GETREDBINARY_DEBUG
+		cvSaveImage("D:\\ImageDebug\\black_dilate.png", black_dilate);
+#endif
 		for (int y = 0; y<h; y++)
 		{
 			unsigned char * binary_row_first = (unsigned char *)(binary->imageData + y*binary->widthStep);
@@ -3565,10 +3569,11 @@ namespace OnLineCard{
 			unsigned char * black_dilate_row_first = (unsigned char *)(black_dilate->imageData + y*black_dilate->widthStep);
 			for (int x = 0; x<w; x++)
 			{
-				red_row_first[x] = (red1_row_first[x] && !black_dilate_row_first[x] && ((!binary_row_first[x]) || red2_row_first[x])) ? 255 : 0;
+				red_row_first[x] = (binary_row_first[x] && !black_dilate_row_first[x] && ((red1_row_first[x]) || red2_row_first[x])) ? 255 : 0;
 			}
 		}
 		rename_image(red_high, red_dilate);
+#if 0
 		cvDilate(red, red_dilate, element, 2);//膨胀图像  
 		for (int y = 0; y<h; y++)
 		{
@@ -3581,6 +3586,7 @@ namespace OnLineCard{
 				red_row_first[x] = (red_row_first[x] || (red_dilate_row_first[x] && (red1_row_first[x] && !black_row_first[x]))) ? 255 : 0;
 			}
 		}
+		cvSaveImage("D:\\ImageDebug\\red02.png", red);
 		cvDilate(red, red_dilate, element, 1);//膨胀图像    
 		for (int y = 0; y<h; y++)
 		{
@@ -3594,15 +3600,17 @@ namespace OnLineCard{
 				}
 			}
 		}
+#endif
 		cvReleaseStructuringElement(&element);
-		//直接使用red_low作为返回值
-		//TODO 此处不太明白red_high存在的意义是什么?
-		*red_binary = red_low;
+#if GETREDBINARY_DEBUG
+		cvSaveImage("D:\\ImageDebug\\red.png", red);
+#endif
+		*red_binary = red;
 		cvReleaseImage(&hsv);
 		cvReleaseImage(&binary);
 		cvReleaseImage(&black);
 		cvReleaseImage(&black_dilate);
-		cvReleaseImage(&red);
+		cvReleaseImage(&red_low);
 		cvReleaseImage(&red_dilate);
 		return TRUE;
 	}

+ 2 - 1
SmartEvaluationLogic/BatchInfo.cpp

@@ -3294,7 +3294,8 @@ int CBatch_Server::UploadResult(Paper_Page* paper)
 		string response;
 		CString url;
 		url.Format(_T("%s/teacher/third/student/upload"), strA2W(g_ServerUrl).c_str());
-		CString strJson = CString(_T("json=")) + strA2W(ToUtf8(json_buf)).c_str();
+		string strJsonContent = UtfToGbk(json_buf);
+		CString strJson = CString(_T("json=")) + strA2W(strJsonContent).c_str();
 		httpClient.HttpPost(url, strJson, response);
 		if (response.find("\"code\":200") != string::npos)
 		{