コード例 #1
0
        /// <summary>
        /// Searches the image for the good features to track.
        /// <para>For each location a Hessian matrix is made and min eig-value is compared against threshold.</para>
        /// </summary>
        /// <param name="image">Image.</param>
        /// <param name="winSize">Window size.</param>
        /// <param name="minEigVal">Minimum eigen value.</param>
        /// <param name="minimalDistance">Minimum distance from two features.</param>
        /// <returns>List of locations that have eigen value larger than <paramref name="minEigVal"/>.</returns>
        public static List <Point> GoodFeaturesToTrack(this Gray <float>[,] image, int winSize = 10, float minEigVal = 0.3f, float minimalDistance = 3)
        {
            var strengthImg = image.CopyBlank();

            var Dx = image.Sobel(1, 0, 3);
            var Dy = image.Sobel(0, 1, 3);

            var Dxx = Dx.MulFloat(Dx).MakeIntegral();
            var Dxy = Dx.MulFloat(Dy).MakeIntegral();
            var Dyy = Dy.MulFloat(Dy).MakeIntegral();

            goodFeaturesToTrack(Dxx, Dxy, Dyy,
                                winSize, minEigVal, strengthImg);

            var filteredStrengthImg = strengthImg.SupressNonMaxima();
            //var filteredStrengthImg = strengthImg;

            IList <float> values;
            var           locations = filteredStrengthImg.FindNonZero(out values);

            var sortedFeatures = locations.Zip(values, (f, s) => new { f, s })
                                 .OrderByDescending(x => x.s)
                                 .Select(x => x.f)
                                 .ToList();

            sortedFeatures = sortedFeatures.EnforceMinimalDistance(minimalDistance);

            return(sortedFeatures);
        }