internal static WeakClassifier Load(float threshold, bool posLargeThanThreshold, float weight, System.Drawing.Rectangle[] rects, int[] weights, ColorType colorType)
        {
            HaarFeature    feature = new HaarFeature(0, rects, weights, colorType);
            WeakClassifier weak    = new WeakClassifier(feature);

            weak._threshold             = threshold;
            weak._posLargeThanThreshold = posLargeThanThreshold;
            weak._weight = weight;

            return(weak);
        }
Exemple #2
0
 private void AddRect(int x1, int y1, int w1, int h1, int ww1, int x2, int y2, int w2, int h2, int ww2)
 {
     Rectangle[] rects = new Rectangle[] {
         new Rectangle(x1, y1, w1, h1),
         new Rectangle(x2, y2, w2, h2),
     };
     int[] weights = new int[] { ww1, ww2 };
     if (_gray)
     {
         HaarFeature gray = new HaarFeature(_weakId, rects, weights, ColorType.Gray);
         _weakClassifiers[_weakId] = new WeakClassifier(gray);
         _weakId++;
     }
     if (_saturation)
     {
         HaarFeature saturation = new HaarFeature(_weakId, rects, weights, ColorType.Saturation);
         _weakClassifiers[_weakId] = new WeakClassifier(saturation);
         _weakId++;
     }
 }
Exemple #3
0
        private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
        {
            if ((e.Node.Tag is WeakClassifier) == false)
            {
                return;
            }
            WeakClassifier weak = e.Node.Tag as WeakClassifier;

            textBox1.Text = weak.GetNumString();

            Image <Gray, Byte> imgBlank = _imgBlank.Copy();
            Image <Bgr, Byte>  imgPos   = _imgPos.Copy();
            HaarFeature        feature  = (HaarFeature)weak.Feature;

            for (int i = 0; i < feature._rects.Length; i++)
            {
                Image <Gray, Byte> mask = new Image <Gray, Byte>(imgBlank.Size);
                int       weight        = feature._weights[i];
                Rectangle rect          = feature._rects[i];
                rect.Height--;
                rect.Width--;
                mask.Draw(rect, new Gray(Math.Abs(weight)), 0);
                if (weight > 0)
                {
                    imgBlank = imgBlank.Add(mask);
                }
                else
                {
                    imgBlank = imgBlank.Sub(mask);
                }

                imgPos.Draw(rect, new Bgr(), 1);
            }
            Image <Gray, Byte> light = imgBlank.ThresholdBinary(new Gray(128), new Gray(255));
            Image <Gray, Byte> dark  = imgBlank.ThresholdBinaryInv(new Gray(127), new Gray(255));

            imgBlank.SetValue(new Gray(255), light);
            imgBlank.SetValue(new Gray(0), dark);
            imageBox1.Image = imgBlank;
            imageBox2.Image = imgPos;
        }