예제 #1
0
파일: Page.cs 프로젝트: kn1m/briefCore
        /// <summary>
        /// Detects the page orientation, with corresponding confidence when using <see cref="PageSegMode.OsdOnly"/>.
        /// </summary>
        /// <remarks>
        /// If using full page segmentation mode (i.e. AutoOsd) then consider using <see cref="AnalyseLayout"/> instead as this also provides a
        /// deskew angle which isn't available when just performing orientation detection.
        /// </remarks>
        /// <param name="orientation">The page orientation.</param>
        /// <param name="confidence">The corresponding confidence score that the detected orientation is correct.</param>
        public void DetectBestOrientation(out Orientation orientation, out float confidence)
        {
            OSResult result = new OSResult();

            result.Init();
            if (TessApi.Native.BaseAPIDetectOS(Engine.Handle, ref result) != 0)
            {
                result.GetBestOrientation(out orientation, out confidence);
            }
            else
            {
                throw new TesseractException("Failed to detect image orientation.");
            }
        }
예제 #2
0
            public static OSResult guessOS(string[] foundServices)
            {
                OSResult result;

                // Initialize objects
                NeuralNetwork.Network net = new NeuralNetwork.Network();

                // Load in data to memory
                if (!File.Exists(Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents", "Gerbil", "memstore", "OSServiceTraining.ini")))
                {
                    return(new OSResult("ERROR", 0.0f));
                }
                string[] trainingData = File.ReadAllLines(Path.Combine(Environment.ExpandEnvironmentVariables("%userprofile%"), "Documents", "Gerbil", "memstore", "OSServiceTraining.ini"));
                // Calculate weights
                PairCounter pc = new PairCounter();

                foreach (string i in trainingData)
                {
                    string sName = i.Split('=')[0];
                    string fOS   = i.Split('=')[1];
                    pc.Add(new Pair(sName, fOS));
                }
                Dictionary <Pair, float> connectionWeights = getPercentagesFromPair(pc.getResults());

                // TODO: Train network
                foreach (KeyValuePair <Pair, float> i in connectionWeights)
                {
                    net.addInput(i.Key.item1);
                    net.addOutput(i.Key.item2, i.Key.item1 + "Connector", i.Value, i.Key.item1);
                }
                // Feed data into tranined neural network
                foreach (string i in foundServices)
                {
                    try
                    {
                        net.fireInput(i);
                    }
                    catch (NeuralNetwork.NodeNotFoundException e)
                    {
                        // Serive does not exist, since we are not in training mode, ignore.
                    }
                    catch
                    {
                        // A serious engine error occured. Throw fatal error.
                        throw new FatalEngineException();
                    }
                }
                // Get outputs
                Dictionary <string, float> results = net.getResults();
                string resultName      = "Unknown";
                float  resultCertainty = 0.0f;
                float  maxCertainty    = 0.0f;

                // Find most likely answer
                foreach (KeyValuePair <string, float> i in results)
                {
                    if (i.Value > resultCertainty)
                    {
                        resultName      = i.Key;
                        resultCertainty = i.Value;
                        maxCertainty   += i.Value;
                    }
                }
                resultCertainty = resultCertainty / maxCertainty;
                result          = new OSResult(resultName, resultCertainty);
                return(result);
            }