Пример #1
0
        public FormViewRect(CascadeClassifier cascade)
        {
            InitializeComponent();
            _cascade = cascade;

            _imgBlank = new Image <Gray, Byte>(cascade.Size);
            _imgBlank.SetValue(new Gray(128.0));
            _imgPos = new Image <Bgr, Byte>(@"D:\My Documents\MATLAB\MyResearch\haarlike\对称正样本\pic004.bmp");
            _imgPos = _imgPos.Copy(new Rectangle(Point.Empty, cascade.Size));

            imageBox1.Image = _imgBlank;
            imageBox2.Image = _imgPos;
            imageBox1.SetZoomScale(16, Point.Empty);
            imageBox2.SetZoomScale(16, Point.Empty);
            InitTree();

            CountClassifiers(cascade);
        }
Пример #2
0
        private void button_viewCascade_Click(object sender, EventArgs e)
        {
            if (_cascadeClassifier == null || _cascadeClassifier.StageCount <= 0)
            {
                _cascadeClassifier = XmlClass.Load(@"cascade_0.000001_0.5_0.99_gray_saturation_20150507_step2neg_height14.xml");
            }
//查看生成的所有特征矩形
//             cascadeClassifier = new CascadeClassifier();
//             cascadeClassifier.Size = _size;
//             WeakClassifierManager.Instance.CreateHaarFeatures(_size.Width, _size.Height / 2, colorType);
//             WeakClassifierManager.Instance.AddSymmetricHaarFeatures(_size.Width, _size.Height, colorType);
//             StageClassifier stage = new StageClassifier(0);
//             stage.Classifiers = WeakClassifierManager.Instance.WeakClassifiers;
//             cascadeClassifier.Classifiers=new StageClassifier[]{stage};
            FormViewRect fv = new FormViewRect(_cascadeClassifier);

            fv.Show();
        }
Пример #3
0
        private void button_train_Click(object sender, EventArgs e)
        {
            textBox_debug.BringToFront();
            if (_cascadeClassifier != null)
            {
                if (MessageBox.Show("已存在分类器,在现有分类器上继续训练吗?", "", MessageBoxButtons.YesNo) == DialogResult.No)
                {
                    _cascadeClassifier = new CascadeClassifier();
                }
            }
            else
            {
                _cascadeClassifier = new CascadeClassifier();
            }
            if (!inited)
            {
                button_loadSamples_Click(sender, e);
//                 WeakClassifierManager.Instance.CreateHaarFeatures(_size.Width, _size.Height , _colorType);
                WeakClassifierManager.Instance.CreateHaarFeatures(_size.Width, _size.Height / 2, _colorType);
                WeakClassifierManager.Instance.AddSymmetricHaarFeatures(_size.Width, _size.Height, _colorType);
            }
            //StageClassifier.ViewId = int.Parse(textBox1.Text);
            GC.Collect();
            GC.WaitForFullGCComplete();
            BackgroundWorker worker = new BackgroundWorker();

            worker.DoWork += new DoWorkEventHandler(
                (a, b) =>
            {
                //cascadeClassifier.Train(posSamples, negSamples, (MyFloat)0.001, (MyFloat)0.5, (MyFloat)0.99);
                _cascadeClassifier.Train(_posSamples, _negSamples, _validateSamples, _size, _targetFalsePositiveRate, _maxFalsePositiveRate, _minHitRate);
            });
            worker.ProgressChanged      += new ProgressChangedEventHandler(worker_ProgressChanged);
            worker.RunWorkerCompleted   += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
            worker.WorkerReportsProgress = true;

            DebugMsg.Init(worker);
            worker.RunWorkerAsync();
            inited = true;
        }
Пример #4
0
        private void CountClassifiers(CascadeClassifier cascade)
        {
            int count = 0, gray = 0, saturation = 0;

            foreach (StageClassifier stage in cascade.Classifiers)
            {
                foreach (WeakClassifier weak in stage.Classifiers)
                {
                    switch (weak.Feature.ColorType)
                    {
                    case ColorType.Gray: gray++;
                        break;

                    case ColorType.Saturation: saturation++;
                        break;
                    }
                    count++;
                }
            }
            this.Text = string.Format("共{0}个弱分类器,其中灰度:{1},饱和度{2}",
                                      count, gray, saturation);
        }
Пример #5
0
 public CascadeDetector(CascadeClassifier cascade, int xStep, int yStep)
 {
     _cascade = cascade;
     _xStep   = xStep;
     _yStep   = yStep;
 }