コード例 #1
0
ファイル: Application.cs プロジェクト: miroslavpokorny/smap
        private DecodedLetters DecodeExtractedLetters(IEnumerable <IEnumerable <CsvRow> > lettersCollections, QrReaderData qrData)
        {
            string currentResult     = null;
            var    isChecksumCorrect = false;

            foreach (var letters in lettersCollections)
            {
                var csvReader        = DataOutput.GetCsvParser(letters);
                var targetName       = "class";
                var featureNames     = csvReader.EnumerateRows(c => c != targetName).First().ColumnNameToIndex.Keys.ToArray();
                var testObservations = csvReader.EnumerateRows(featureNames).ToF64Matrix();
                testObservations.Map(p => p / 255);

                var model       = ClassificationNeuralNetModel.Load(() => new StreamReader("network.xml"));
                var predictions = model.Predict(testObservations);

                var stringBuilder = new StringBuilder();
                foreach (var prediction in predictions)
                {
                    stringBuilder.Append(Math.Abs(prediction - -1) < 0.01 ? '-' : Alphabet.Base32Alphabet.ToString()[(int)prediction]);
                }

                currentResult = stringBuilder.ToString();

                isChecksumCorrect = Sha1Helper.IsChecksumCorrect(currentResult, qrData.MetaData.Checksum);

                if (isChecksumCorrect)
                {
                    break;
                }
            }

            return(new DecodedLetters {
                Letters = currentResult, IsChecksumOk = isChecksumCorrect
            });
        }