private static Tuple <String, List <Circle> > DetectExamCode(Bitmap img, List <Rect> horizontalFlgRects, List <Rect> verticalFlgRects) { string examId = ""; List <Circle> lstCircles = new List <Circle>(); Circle c; bool found; for (int i = 1; i < 4; i++) { found = false; for (int j = 1; j < 11; j++) { Rect r1 = horizontalFlgRects[i]; Rect r2 = verticalFlgRects[j]; Point c1 = r1.GetCenterPoint(); Point c2 = r2.GetCenterPoint(); c = new Circle(new Point(c1.x, c2.y), Constant.DEFAULT_CIRCLE_RADIUS); int nOfBlackInCircle = CommonImageProcessing.CountNumberOfBlackPixelInCircle(img, c, -5); if (nOfBlackInCircle >= Constant.NUMBER_OF_CIRCLE_BLACK_PIXEL_TO_BE_CONSIDERED_INFO_AS_CHOOSEN) { if (found) { examId = "-"; } else { found = true; if (examId != "-") { examId = (j - 1).ToString() + examId; } } lstCircles.Add(c); } } if (!found) { examId = examId + "*"; } } return(new Tuple <string, List <Circle> >(examId, lstCircles)); }
private static Tuple <List <Char>, List <Circle>, List <Point> > DetectStudentAnswer(Bitmap img, List <Rect> horizontalFlgRects, List <Rect> verticalFlgRects) { int numberOfQuestion = Globals.numberOfQuestion; List <Char> answers = new List <Char>(); List <Circle> lstCircles = new List <Circle>(); List <Point> borderPoints = new List <Point>(); for (int i = 0; i < numberOfQuestion + 1; i++) { answers.Add('*'); borderPoints.Add(new Point(-100, -100)); } int nHorizontalRect = horizontalFlgRects.Count; int nVerticalRect = verticalFlgRects.Count; Char currentAns = 'A'; int currentQuestion; int colStartQuestion = 1; int numberOfRow = (nVerticalRect - 12); Circle c; for (int i = nHorizontalRect - 1; i >= 1; i--) { currentQuestion = colStartQuestion; for (int j = 11; j < nVerticalRect - 1; j++) { if (currentQuestion > numberOfQuestion) { break; } Rect r1 = horizontalFlgRects[i]; Rect r2 = verticalFlgRects[j]; Point c1 = r1.GetCenterPoint(); Point c2 = r2.GetCenterPoint(); if (currentAns == 'A') { borderPoints[currentQuestion] = new Point(c1.x, c2.y); } c = new Circle(new Point(c1.x, c2.y), Constant.DEFAULT_CIRCLE_RADIUS); int nOfBlackInCircle = CommonImageProcessing.CountNumberOfBlackPixelInCircle(img, c, 8); if (nOfBlackInCircle >= Constant.NUMBER_OF_CIRCLE_BLACK_PIXEL_TO_BE_CONSIDERED_ANSWER_AS_CHOOSEN) { if (answers[currentQuestion] == '*') { answers[currentQuestion] = currentAns; } else { answers[currentQuestion] = '-'; } lstCircles.Add(c); } currentQuestion++; if (currentQuestion > numberOfQuestion) { break; } } if (currentAns == 'E') { currentAns = 'A'; colStartQuestion += numberOfRow; } else { currentAns++; } } return(new Tuple <List <char>, List <Circle>, List <Point> >(answers, lstCircles, borderPoints)); }