Exemplo n.º 1
0
        //开始手势识别
        private bool StartMatch()
        {
            if (Smooth())
            {
                ShowSmoothPoint();
                CreateVectors();

                //识别
                if (Mode == RUN_MODE.ACTIVE)
                {
                    if (!TestForMatch())
                    {
                        MessageBox.Show("An internal error accured when matching!", "GestureStudy", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return(false);
                    }
                    else
                    {
                        ShowResult();
                    }
                }
                //学习
                else if (Mode == RUN_MODE.LEARNING)
                {
                    //保存新的手势并重新训练网络
                    if (MessageBox.Show("Do you want to save this gesture?", "GestureStudy", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        string name = Microsoft.VisualBasic.Interaction.InputBox("Name for this gesture?", "GestureStudy", "", this.Left + 100, this.Top + 100);
                        data.AddPattern(Vectors, name);
                        NumValidPatterns++;

                        net              = new NeuralNet(Useful.NUM_VECTORS * 2, NumValidPatterns, Useful.NUM_HIDDEN_NEURONS, Useful.LEARNING_RATE);
                        net.SendMessage += new NeuralNet.DelegateOfSendMessage(ShowMessage);

                        txtState.BackColor = Color.FromKnownColor(KnownColor.Control);
                        RenewNetwork();

                        Mode = RUN_MODE.ACTIVE;
                    }
                }
            }
            else
            {
                MessageBox.Show("Too few points captured, please draw line slowly!", "GestureStudy", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Clear();
                ClearDraw();
            }

            return(true);
        }
Exemplo n.º 2
0
 //初始化数据
 private void InitData()
 {
     Mode             = RUN_MODE.UNREADY;
     NumValidPatterns = Useful.NUM_PATTERNS;
     NumSmoothPoints  = Useful.NUM_VECTORS + 1;
     HighestOutput    = 0.0;
     BestMatch        = -1;
     Match            = -1;
     RawPath          = new List <Point>();
     SmoothPath       = new List <Point>();
     Vectors          = new List <double>();
     data             = new GestureData(NumValidPatterns, Useful.NUM_VECTORS);
     net              = new NeuralNet(Useful.NUM_VECTORS * 2, NumValidPatterns, Useful.NUM_HIDDEN_NEURONS, Useful.LEARNING_RATE);
     net.SendMessage += new NeuralNet.DelegateOfSendMessage(ShowMessage);
 }
Exemplo n.º 3
0
        //使用新的参数重建神经网络
        private void RenewNetwork()
        {
            Useful.LEARNING_RATE      = (double)(txtLearning.Value);
            Useful.ERROR_THRESHOLD    = (double)(txtThreshold.Value);
            Useful.NUM_HIDDEN_NEURONS = (int)(txtHidden.Value);
            Useful.WITH_MOMENTUM      = chkMomentum.Checked;
            Useful.MOMENTUM           = (double)(txtMomentum.Value);
            Useful.WITH_NOISE         = chkNoise.Checked;
            Useful.MAX_NOISE_TO_ADD   = (double)(txtNoise.Value);

            net              = new NeuralNet(Useful.NUM_VECTORS * 2, NumValidPatterns, Useful.NUM_HIDDEN_NEURONS, Useful.LEARNING_RATE);
            net.SendMessage += new NeuralNet.DelegateOfSendMessage(ShowMessage);

            txtState.Text = "Training";
            TrainNetwork();
            txtState.Text = "Ready";
        }