public WeakClassifier(HaarFeatureType type, int height, int width, int x, int y)
        {
            if (type == HaarFeatureType.Type1 && width % 2 != 0)
            {
                throw new ArgumentException("Width must be even", nameof(width));
            }
            if (type == HaarFeatureType.Type2 && height % 2 != 0)
            {
                throw new ArgumentException("Height must be even", nameof(height));
            }
            if (type == HaarFeatureType.Type3 && width % 3 != 0)
            {
                throw new ArgumentException("Width must be odd and divisible by 3", nameof(width));
            }
            if (type == HaarFeatureType.Type4 && height % 3 != 0)
            {
                throw new ArgumentException("Height must be odd and divisible by 3", nameof(height));
            }
            if (type == HaarFeatureType.Type5)
            {
                if (width % 2 != 0)
                {
                    throw new ArgumentException("Width must be odd", nameof(width));
                }
                if (height % 2 != 0)
                {
                    throw new ArgumentException("Height must be odd", nameof(height));
                }
            }

            Type   = type;
            XPos   = x;
            YPos   = y;
            Width  = width;
            Height = height;

            Parity    = 1;
            Threshold = 0.2;
        }
Exemple #2
0
        public static List <WeakClassifier> CreateFeatures(HaarFeatureType type, int maxHeight, int maxWidth)
        {
            var features = new List <WeakClassifier>();

            var heightBreak = false;
            var widthBreak  = false;
            var yBreak      = false;

            for (int i = 1; i <= maxHeight; i++)
            {
                for (int j = 1; j <= maxWidth; j++)
                {
                    for (int y = 0; y <= maxHeight - i; y++)
                    {
                        for (int x = 0; x <= maxWidth - j; x++)
                        {
                            try
                            {
                                features.Add(new WeakClassifier((HaarFeatureType)type, i, j, x, y));
                            }
                            catch (ArgumentException ae)
                            {
                                if (ae.ParamName == "width")
                                {
                                    widthBreak = true;
                                    break;
                                }
                                if (ae.ParamName == "height")
                                {
                                    heightBreak = true;
                                    break;
                                }
                            }
                        }

                        if (yBreak)
                        {
                            yBreak = false;
                            continue;
                        }
                        if (widthBreak || heightBreak)
                        {
                            break;
                        }
                    }

                    if (widthBreak)
                    {
                        widthBreak = false;
                        continue;
                    }
                    if (heightBreak)
                    {
                        break;
                    }
                }

                if (heightBreak)
                {
                    heightBreak = false;
                    continue;
                }
            }

            return(features);
        }
 public WeakClassifier(HaarFeatureType type, int height, int width)
 {
     Type = type;
 }