예제 #1
0
        /// <summary>
        /// Parses the result string to an output string for the Text-To-Speech algorithm.
        /// Customizes the output string in dependency of the number of list elements.
        /// It is differentiated between no result, one result element, more than one result elements and occuring errors.s
        /// </summary>
        /// <param name="result">The result string from object detection which contains the values and the probabilities.</param>
        /// <returns>Parsed string that contains the prediction with value(s), the probability/ies and the number of elements.</returns>
        private string ParseResult(string result)
        {
            if (!string.IsNullOrEmpty(result))
            {
                var parsedPrediction = PythonOutputParser.ParseToListOfPredictions(result);
                //bool isNumber = Directory.GetDirectories(Properties.Resources.PythonModelPath).Any(d => d.Contains(Properties.Resources.ModelNumber));
                bool          isNumber      = new SettingsController().GetTfModelMode() == Properties.Resources.ModelNumber;
                StringBuilder stringBuilder = new StringBuilder();

                if (parsedPrediction.Count == 0)
                {
                    stringBuilder.Append(Properties.Resources.NoResultFound);
                    return(stringBuilder.ToString());
                }
                if (parsedPrediction.Count == 1)
                {
                    stringBuilder.Append(isNumber ? Properties.Resources.FoundNumber : Properties.Resources.FoundLetter);

                    var number      = parsedPrediction[0].PredictedValue;
                    var probability = parsedPrediction[0].PredictionPercentage;
                    stringBuilder.Append(number);
                    stringBuilder.Append(Properties.Resources.Probability);
                    stringBuilder.Append(probability);
                    stringBuilder.Append(Properties.Resources.Percent);
                    stringBuilder.Append(Properties.Resources.Comma);
                }
                else if (parsedPrediction.Count >= 2)
                {
                    stringBuilder.Append(Properties.Resources.FoundTheFollowing);

                    string numberOfChunksFound = parsedPrediction.Count.ToString();
                    stringBuilder.Append(numberOfChunksFound);

                    stringBuilder.Append(isNumber ? Properties.Resources.FoundNumbers : Properties.Resources.FoundLetters);

                    foreach (var pred in parsedPrediction)
                    {
                        var number      = pred.PredictedValue;
                        var probability = pred.PredictionPercentage;

                        stringBuilder.Append(number);
                        stringBuilder.Append(Properties.Resources.Probability);
                        stringBuilder.Append(probability);
                        stringBuilder.Append(Properties.Resources.Percent);
                        stringBuilder.Append(Properties.Resources.Comma);
                    }
                }

                stringBuilder.Append(Properties.Resources.ThatIsAll);

                return(stringBuilder.ToString());
            }
            return(Properties.Resources.ThereHasBeenAnError);
        }
예제 #2
0
        /// <summary>
        /// Initializes the ProcessStartInfo that is used for the object detection process by setting the command as script to execute
        /// and the arguments as additional information for the python script to process.
        /// </summary>
        /// <param name="command">The python script that is executed as own process.</param>
        /// <param name="args">Additional (console) arguments that are passed to the process.</param>
        /// <returns>ProcessStartInfo that is used when starting the process.</returns>
        private ProcessStartInfo InitProcessStartInfo(string command, string args)
        {
            var tfModelMode = new SettingsController().GetTfModelMode();

            ProcessStartInfo processStartInfo = new ProcessStartInfo
            {
                FileName               = new SettingsController().GetPythonInterpreterPath(), //custom path from settings file
                Arguments              = $"\"{command}\" \"{args}\" \"{tfModelMode}\"",       //arguments (image path and tfmodelmode)
                UseShellExecute        = false,                                               // don't use windows cmd
                CreateNoWindow         = true,
                RedirectStandardOutput = true,                                                // Any output, generated by application will be redirected back
                RedirectStandardError  = true                                                 // Any error in standard output will be redirected back (for example exceptions)
            };

            return(processStartInfo);
        }