private void FindStampNumber(RecognitionResult recResult) { if (_config.Ocr.Stamp.TestLevel == StampTestLevel.None) { recResult.StampOk = true; return; } if (recResult.ResultCode < 0) { recResult.StampOk = false; return; } if (_config.Ocr.Stamp.TestLevel != StampTestLevel.Halftone && recResult.StampResult == StampResult.YES) { recResult.StampOk = true; return; } Logger.LogVerbose(Message.RecognizerStampNumber, recResult.StampNumber, recResult.StampNumberAlts[0], recResult.StampNumberAlts[1], recResult.StampNumberAlts[2], recResult.StampNumberAlts[3]); if (recResult.StampResult != StampResult.YES && recResult.StampResult != StampResult.FAINT) { recResult.StampOk = false; return; } int iStampNumber; if (!int.TryParse(recResult.StampNumber, out iStampNumber)) { recResult.StampOk = false; return; } if (iStampNumber == _electionManager.SourceData.Uik) { recResult.StampOk = true; return; } var uikStr = _electionManager.SourceData.Uik.ToString("0000"); if (СheckAlternatives(uikStr, recResult.StampNumberAlts)) { recResult.StampNumber = uikStr; recResult.StampOk = true; return; } if (_electionManager.SourceData == null || !AllowSuperiorStamp) { recResult.StampOk = false; return; } var blank = _electionManager.SourceData.Blanks[recResult.BulletinNumber]; for (var i = 0; i < blank.Sections.Length; i++) { var electionNum = blank.Sections[i]; var election = _electionManager.SourceData.GetElectionByNum(electionNum); if (election.StampCommittees. Any(stampCommittee => stampCommittee.Num > 0 && iStampNumber == stampCommittee.Num)) { recResult.StampOk = true; return; } } recResult.StampOk = false; }
private void CreateStampInfo(RecognitionResult recResult) { if (_config.Ocr.Stamp.TestLevel == StampTestLevel.None || recResult.ResultCode != OcrRecognitionResult.OK) { recResult.StampReasonCode = "not-checked"; recResult.StampDescription = "не проверялась"; recResult.StampShortDescription = recResult.StampDescription; return; } switch (recResult.StampResult) { case StampResult.YES: switch (_config.Ocr.Stamp.TestLevel) { case StampTestLevel.Found: recResult.StampReasonCode = "found"; recResult.StampDescription = "присутствует"; break; case StampTestLevel.Halftone: if (recResult.StampOk) { recResult.StampReasonCode = "recognized"; recResult.StampDescription = "распознана"; } else { recResult.StampReasonCode = "not-match-uik-number"; recResult.StampDescription = "не соответствует номеру УИК"; } break; default: recResult.StampReasonCode = "valid"; recResult.StampDescription = "действительная"; break; } break; case StampResult.EMPTY: recResult.StampReasonCode = "empty"; recResult.StampDescription = "отсутствует"; break; case StampResult.FAINT: recResult.StampReasonCode = "faint"; recResult.StampDescription = "слишком бледная"; break; case StampResult.BADPRINT: recResult.StampReasonCode = "bad-print"; recResult.StampDescription = "неверная"; break; case StampResult.CALL_ERROR: recResult.StampReasonCode = "recognizing-error"; recResult.StampDescription = "ошибка при распознавании"; recResult.StampShortDescription = "ошибка распознавания"; break; case StampResult.BADLINES: recResult.StampReasonCode = "bad-lines"; recResult.StampDescription = "не обнаружены необходимые линии"; recResult.StampShortDescription = "линии"; break; default: recResult.StampReasonCode = "not-recognized"; recResult.StampDescription = "не распознана"; break; } if (recResult.StampShortDescription == null) recResult.StampShortDescription = recResult.StampDescription; }
private RecognitionResult CreateRecognitionResult( int recResultCode, int[][] marks, bool[] sectionsValidity, StampResult stampResult, string stampNumber, string[] stampNumberAlts) { var recResult = new RecognitionResult(recResultCode) { StampResult = stampResult, StampNumber = stampNumber, StampNumberAlts = stampNumberAlts, BulletinNumber = recResultCode != (int)OcrRecognitionResult.MARK ? _ocr.BulletinNumber : -1, Marks = marks, SectionsValidity = sectionsValidity }; FindStampNumber(recResult); CreateStampInfo(recResult); if (recResult.ResultCode == OcrRecognitionResult.OK && recResult.StampOk) { if (recResult.BulletinNumber < 0 || recResult.BulletinNumber >= _electionManager.SourceData.Blanks.Length) { recResult.BlankType = BlankType.Bad; recResult.ResultDescription = "Недопустимый номер бюллетеня " + recResult.BulletinNumber; } else { var blank = _electionManager.SourceData.Blanks[recResult.BulletinNumber]; if (_electionManager.SourceData.IsVotingModeValidForBlank(blank, _recognitionStartVotingMode)) { Logger.LogVerbose(Message.RecognizerBulletinRecognized); for (int i = 0; i < recResult.Marks.Length; i++) { var curSectionMarks = recResult.Marks[i]; if (recResult.SectionsValidity[i]) { recResult.BlankType = BlankType.Valid; break; } if (curSectionMarks.Length > 0) recResult.BulletinWithExtraLabels = true; else recResult.BulletinWithoutLabels = true; } if (recResult.BlankType != BlankType.Valid) { if (recResult.BulletinWithExtraLabels) recResult.BlankType = BlankType.TooManyMarks; if (recResult.BulletinWithoutLabels) recResult.BlankType = BlankType.NoMarks; } recResult.ResultDescription = string.Format( "Бюллетень N {0} {1}. Печать: {2}. {3}. Время: {4}", recResult.BlankTypeDescription, blank.Marker, recResult.StampDescription, GetSquareDescription(recResultCode, recResult.Marks), DateTime.Now.ToString("HH:mm:ss.fff")); Logger.LogVerbose(Message.RecognizerBulletinResult, recResult.BlankTypeDescription, _recognitionStartVotingMode); } else { recResult.BlankType = BlankType.BadMode; recResult.ResultDescription = "Бюллетень не имеет текущего режима голосования"; Logger.LogVerbose(Message.RecognizerWrongModeForBulletin); } } } else { recResult.BlankType = BlankType.Bad; CreateBadBulletinInfo(recResult); recResult.ResultDescription = string.Format("Бюллетень неустановленной формы ({0}).", recResult.BadBulletinDescription); Logger.LogVerbose(Message.RecognizerNuf, recResult.ResultDescription); } var blankConfig = _config.Blanks.Get(recResult.BlankType, _sheetType); if (recResult.BlankType == BlankType.Bad && recResult.BadBulletinReason == BadBulletinReason.Stamp && _config.Blanks.Get(BlankType.BadStamp) != null) { blankConfig = _config.Blanks.Get(BlankType.BadStamp); } var imageFilePrefixStringBuilder = new StringBuilder(); imageFilePrefixStringBuilder.Append(blankConfig.ImageFilePrefix); if (!string.IsNullOrEmpty(recResult.BadBulletinFilePrefix)) { imageFilePrefixStringBuilder.Append('-'); imageFilePrefixStringBuilder.Append(recResult.BadBulletinFilePrefix); } if (_config.Ocr.Stamp.TestLevel == StampTestLevel.Halftone) { imageFilePrefixStringBuilder.Append('-'); imageFilePrefixStringBuilder.Append(recResult.StampNumber); } recResult.ImageFilePrefix = imageFilePrefixStringBuilder.ToString(); recResult.Marking = blankConfig.Marking; if (_recognitionStartVotingMode == VotingMode.Test) blankConfig = _config.Blanks.Get(BlankType.Test); recResult.ImageSavingType = blankConfig.ImageSavingType; return recResult; }
private void AddVotingResult(RecognitionResult recResult) { try { var votingResult = new VotingResult( recResult.BlankType, recResult.BulletinNumber, recResult.StampNumber, recResult.BadBulletinReason.ToString(), recResult.BadStampReason, recResult.Marks, recResult.SectionsValidity); _votingResultManager.AddVotingResult( votingResult, _recognitionStartVotingMode, _scannerManager.IntSerialNumber); } catch (Exception ex) { Logger.LogError(Message.RecognizerAddVotingResultError, ex); } }
private static void CreateBadBulletinInfo(RecognitionResult recResult) { if (recResult.ResultCode == OcrRecognitionResult.OK && (recResult.StampResult != StampResult.YES || !recResult.StampOk)) { recResult.BadBulletinFilePrefix = "BAD-STAMP"; recResult.BadBulletinReason = BadBulletinReason.Stamp; recResult.BadStampReason = recResult.StampReasonCode; recResult.BadBulletinDescription = "Печать - " + recResult.StampDescription; recResult.BadBulletinShortDescription = "Печать - " + recResult.StampShortDescription; return; } recResult.BadBulletinReason = BadBulletinReason.Marker; switch (recResult.ResultCode) { case OcrRecognitionResult.ERROR: recResult.BadBulletinFilePrefix = "REC-ERROR"; recResult.BadBulletinDescription = "Ошибка при возврате из функции"; recResult.BadBulletinShortDescription = "Возврат из функции"; break; case OcrRecognitionResult.NUF: recResult.BadBulletinFilePrefix = "NUF"; recResult.BadBulletinDescription = "Без детализации"; recResult.BadBulletinShortDescription = recResult.BadBulletinDescription; break; case OcrRecognitionResult.BRK: recResult.BadBulletinFilePrefix = "BRK"; recResult.BadBulletinDescription = "Распознавание было прервано"; recResult.BadBulletinShortDescription = "распознавание прервано"; break; case OcrRecognitionResult.MARK: recResult.BadBulletinFilePrefix = "MARK"; recResult.BadBulletinDescription = "Не удалось обнаружить или узнать маркер"; recResult.BadBulletinShortDescription = "Маркер"; break; case OcrRecognitionResult.SKEW: recResult.BadBulletinFilePrefix = "SKEW"; recResult.BadBulletinReason = BadBulletinReason.Lines; recResult.BadBulletinDescription = "Не удалось локализовать требуемые линии"; recResult.BadBulletinShortDescription = "Линии"; break; case OcrRecognitionResult.REFP: recResult.BadBulletinFilePrefix = "REFP"; recResult.BadBulletinReason = BadBulletinReason.Refp; recResult.BadBulletinDescription = "Не удалось локализовать опорные точки"; recResult.BadBulletinShortDescription = "Опорные точки"; break; case OcrRecognitionResult.FSQR: recResult.BadBulletinFilePrefix = "FSQR"; recResult.BadBulletinReason = BadBulletinReason.Squares; recResult.BadBulletinDescription = "Не удалось локализовать квадраты"; recResult.BadBulletinShortDescription = "Квадраты"; break; case OcrRecognitionResult.CLRTOP: recResult.BadBulletinFilePrefix = "CLRTOP"; recResult.BadBulletinDescription = "При удалении черного сверху съели почти все"; recResult.BadBulletinShortDescription = "Черное сверху"; break; case OcrRecognitionResult.CLRBOT: recResult.BadBulletinFilePrefix = "CLRBOT"; recResult.BadBulletinDescription = "При удалении черного снизу съели почти все"; recResult.BadBulletinShortDescription = "Черное снизу"; break; case OcrRecognitionResult.CALL: recResult.BadBulletinFilePrefix = "CALL"; recResult.BadBulletinDescription = "Ошибка вызова функции"; recResult.BadBulletinShortDescription = "Вызов функции"; break; case OcrRecognitionResult.SCTLINE: recResult.BadBulletinFilePrefix = "SCTLINE"; recResult.BadBulletinReason = BadBulletinReason.Lines; recResult.BadBulletinDescription = "Не удалось обнаружить нижнюю линию секции"; recResult.BadBulletinShortDescription = "Нижняя линия"; break; case OcrRecognitionResult.BULNUM: recResult.BadBulletinFilePrefix = "BULNUM"; recResult.BadBulletinDescription = "Недопустимый номер бюллетеня"; recResult.BadBulletinShortDescription = "Номер бюллетеня"; break; default: recResult.BadBulletinFilePrefix = "UNKNOWN"; recResult.BadBulletinDescription = "Описание неизвестно"; recResult.BadBulletinShortDescription = recResult.BadBulletinDescription; break; } }
private void WriteRecognitionResultToLog( RecognitionResult recResult, StampResult stampResult, string stampNumber, string additionalInfo) { try { var recLogSb = new StringBuilder(); recLogSb.Append(_recognitionStartVotingMode); recLogSb.Append(','); recLogSb.Append(GetImageFileName(recResult.ImageFilePrefix)); recLogSb.Append(','); recLogSb.Append(_ocr.BulletinNumber); recLogSb.Append(','); recLogSb.Append(_scannerManager.SerialNumber); recLogSb.Append(','); recLogSb.Append(recResult.IntResultCode); recLogSb.Append(','); recLogSb.Append(stampNumber); recLogSb.Append(','); recLogSb.Append(stampResult); recLogSb.Append(','); recLogSb.Append(additionalInfo); if (!_scannerManager.SheetProcessingSession.Closed) { recLogSb.Append('\t'); recLogSb.Append(_scannerManager.SheetProcessingSession.Id); } _recognitionResultLogger.LogInfo(Message.RecognizerLog, recLogSb.ToString()); } catch (Exception ex) { Logger.LogError(Message.RecognizerLogError, ex); } }