コード例 #1
0
ファイル: BaseClassifier.cs プロジェクト: denjiz/tld
        private int GetPatchCode(Image <Gray, byte> patch)
        {
            PixelComparisonF[] comparisons = _pixelComparisonScheduler.GetComparisonsForClassifier(_myIndex);

            // stretch comparisons over the patch
            StretchComparisons(patch.Size, comparisons, _strechedComparisons);

            // calculate the code
            int binaryCode = 0;

            for (int i = 0; i < _strechedComparisons.Length; i++)
            {
                PixelComparisonF strechedComparison = _strechedComparisons[i];
                double           i1 = patch[Point.Round(strechedComparison.Pixel1)].Intensity;
                double           i2 = patch[Point.Round(strechedComparison.Pixel2)].Intensity;

                // actual bit
                if (i1 > i2)
                {
                    binaryCode = binaryCode | bitMask[i];
                }
            }

            return(binaryCode);
        }
コード例 #2
0
        public void SchedulePixelComparisons()
        {
            List <PixelComparisonF> allPixelComparisons = new List <PixelComparisonF>(_allPixelComparisons);

            _scheduledPixelComparisons = new PixelComparisonGroupF[_baseClassifierCount];
            for (int i = 0; i < _baseClassifierCount; i++)
            {
                _scheduledPixelComparisons[i]       = new PixelComparisonGroupF();
                _scheduledPixelComparisons[i].Value = new PixelComparisonF[_maxComparisonsPerClassifier];
            }

            _comparisonsPerClassifier = 0;
            while (allPixelComparisons.Count >= _baseClassifierCount && _comparisonsPerClassifier < _maxComparisonsPerClassifier)
            {
                for (int i = 0; i < _baseClassifierCount; i++)
                {
                    PixelComparisonF comparison = allPixelComparisons.RandomElement();
                    _scheduledPixelComparisons[i].Value[_comparisonsPerClassifier] = comparison;
                    allPixelComparisons.Remove(comparison);
                }

                _comparisonsPerClassifier += 1;
            }

            if (_comparisonsPerClassifier < _maxComparisonsPerClassifier)
            {
                for (int i = 0; i < _baseClassifierCount; i++)
                {
                    Array.Resize(ref _scheduledPixelComparisons[i].Value, _comparisonsPerClassifier);
                }
            }
        }
コード例 #3
0
ファイル: BaseClassifier.cs プロジェクト: denjiz/tld
        private void StretchComparisons(Size size, PixelComparisonF[] comparisons, PixelComparisonF[] strechedComparisons)
        {
            int width  = size.Width;
            int height = size.Height;

            for (int i = 0; i < comparisons.Length; i++)
            {
                PixelComparisonF comparison     = comparisons[i];
                PointF           strechedPixel1 = comparisons[i].Pixel1.Multiply(width - 1, height - 1);
                PointF           strechedPixel2 = comparisons[i].Pixel2.Multiply(width - 1, height - 1);
                strechedComparisons[i] = new PixelComparisonF(strechedPixel1, strechedPixel2);
            }
        }
コード例 #4
0
ファイル: BaseClassifier.cs プロジェクト: denjiz/tld
        public Point[][] StretchComparisonsOnWindow(int windowIndex)
        {
            // get normalized comparisons
            PixelComparisonF[] normalizedComparisons = _pixelComparisonScheduler.GetComparisonsForClassifier(_myIndex);
            int comparisons = normalizedComparisons.Length;

            // allocate space for stretched comparisons
            Point[][] stretchedComparisons = new Point[comparisons][];
            for (int i = 0; i < comparisons; i++)
            {
                stretchedComparisons[i] = new Point[2];
            }

            // get scanning window and its parameters
            ScanningWindow window             = _scanningWindowGenerator.ScanningWindows[windowIndex].ScanningWindow;
            Point          windowLocation     = window.Location;
            Size           windowSize         = window.Size;
            int            windowWidth        = windowSize.Width;
            int            windowHeight       = windowSize.Height;
            int            windowWidthMinus1  = windowWidth - 1;
            int            windowHeightMinus1 = windowHeight - 1;

            // calculate stretched comparisons
            for (int i = 0; i < comparisons; i++)
            {
                PixelComparisonF normalizedComparison = normalizedComparisons[i];
                Point[]          stretchedComparison  = stretchedComparisons[i];

                Point stretchedPixel1 = new Point((int)Math.Round(normalizedComparison.Pixel1.X * windowWidthMinus1 + windowLocation.X), (int)Math.Round(normalizedComparison.Pixel1.Y * windowHeightMinus1 + windowLocation.Y));
                Point stretchedPixel2 = new Point((int)Math.Round(normalizedComparison.Pixel2.X * windowWidthMinus1 + windowLocation.X), (int)Math.Round(normalizedComparison.Pixel2.Y * windowHeightMinus1 + windowLocation.Y));

                stretchedComparison[0] = stretchedPixel1;
                stretchedComparison[1] = stretchedPixel2;
            }

            return(stretchedComparisons);
        }