Exemplo n.º 1
0
        private void btnRecognize_Click(object sender, EventArgs e)
        {
            var ds = new DownSample(_entryImage);

            _downSampled = ds.DoDownSampling(_downSampleWidth, _downSampleHeight);
            pnlSample.Invalidate();

            char   bestChar     = '?';
            double bestDistance = double.MaxValue;

            foreach (char c in _letterDictionary.Keys)
            {
                double[] data = _letterDictionary[c];
                double   dist = _distCalc.Calculate(data, _downSampled);

                if (dist < bestDistance)
                {
                    bestDistance = dist;
                    bestChar     = c;
                }
            }

            MessageBox.Show(@"The letter closely matches: " + bestChar, @"Recognize");
            ClearEntry();
        }
Exemplo n.º 2
0
        private void ClearEntry()
        {
            Brush whiteBrush = new SolidBrush(Color.White);

            _entryGraphics.FillRectangle(whiteBrush, 0, 0, pnlEntry.Width, pnlEntry.Height);
            pnlEntry.Invalidate();
            var ds = new DownSample(_entryImage);

            _downSampled = ds.DoDownSampling(_downSampleWidth, _downSampleHeight);
            pnlSample.Invalidate();
        }
Exemplo n.º 3
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            var ds = new DownSample(_entryImage);

            _downSampled = ds.DoDownSampling(_downSampleWidth, _downSampleHeight);
            pnlSample.Invalidate();
            const string prompt         = "The letter you drew was:";
            const string title          = "Input Letter";
            const string defaultMessage = "";

            Int32 xPos = (SystemInformation.WorkingArea.Width / 2) - 200;
            Int32 yPos = (SystemInformation.WorkingArea.Height / 2) - 100;

            bool valid = false;

            foreach (double t in _downSampled)
            {
                if (t > 0.1)
                {
                    valid = true;
                }
            }

            if (!valid)
            {
                MessageBox.Show(@"Please draw a letter before adding it.");
                return;
            }

            string result = Interaction.InputBox(prompt, title, defaultMessage, xPos, yPos);

            if (result != null)
            {
                result = result.ToUpper();
                if (result.Length == 0)
                {
                    MessageBox.Show(@"Please enter a letter.");
                }
                else if (result.Length > 1)
                {
                    MessageBox.Show(@"Please only enter one letter.");
                }
                else if (_letterDictionary.ContainsKey(result[0]))
                {
                    MessageBox.Show(@"That letter is already defined. Please delete it first.");
                }
                else
                {
                    lstLetters.Items.Add(result);
                    _letterDictionary.Add(result[0], _downSampled);
                    ClearEntry();
                }
            }
        }