private static Rectangle process(Gray<byte>[,] probabilityMap, Rectangle roi, TermCriteria termCriteria, out CentralMoments centralMoments) { Rectangle imageArea = new Rectangle(0, 0, probabilityMap.Width(), probabilityMap.Height()); Rectangle searchWindow = roi; RawMoments moments = new RawMoments(order: 1); // Mean shift with fixed number of iterations int i = 0; double shift = Byte.MaxValue; while (termCriteria.ShouldTerminate(i, shift) == false && !searchWindow.IsEmptyArea()) { // Locate first order moments moments.Compute(probabilityMap, searchWindow); int shiftX = (int)(moments.CenterX - searchWindow.Width / 2f); int shiftY = (int)(moments.CenterY - searchWindow.Height / 2f); // Shift the mean (centroid) searchWindow.X += shiftX; searchWindow.Y += shiftY; // Keep the search window inside the image searchWindow.Intersect(imageArea); shift = System.Math.Abs((double)shiftX) + System.Math.Abs((double)shiftY); //for term criteria only i++; } if (searchWindow.IsEmptyArea() == false) { // Locate second order moments and perform final shift moments.Order = 2; moments.Compute(probabilityMap, searchWindow); searchWindow.X += (int)(moments.CenterX - searchWindow.Width / 2f); searchWindow.Y += (int)(moments.CenterY - searchWindow.Height / 2f); // Keep the search window inside the image searchWindow.Intersect(imageArea); } centralMoments = new CentralMoments(moments); // moments to be used by camshift return searchWindow; }
internal override void Compute(IImage image) { RawMoments rawMoments = new RawMoments(Order); rawMoments.Compute(image); this.Compute(rawMoments); }
/// <summary> /// Computes moments for the provided image. /// </summary> /// <param name="image">Image.</param> /// <param name="area">Area</param> public void Compute(Gray <float>[,] image, Rectangle area) { RawMoments rawMoments = new RawMoments(Order); rawMoments.Compute(image, area); this.Compute(rawMoments); }
/// <summary> /// Computes moments for the provided image. /// </summary> /// <param name="image">Image.</param> /// <param name="area">Area</param> public void Compute(Gray <float>[,] image, Rectangle area) { RawMoments raw = new RawMoments(Order); raw.Compute(image, area); CentralMoments center = new CentralMoments(raw); this.Compute(center); }
/// <summary> /// Computes moments for the provided image. /// </summary> /// <param name="image">Image.</param> /// <param name="area">Area</param> public void Compute(Gray<float>[,] image, Rectangle area) { RawMoments raw = new RawMoments(Order); raw.Compute(image, area); CentralMoments center = new CentralMoments(raw); this.Compute(center); }
/// <summary> /// Computes moments for the provided image. /// </summary> /// <param name="image">Image.</param> /// <param name="area">Area</param> public void Compute(Gray<float>[,] image, Rectangle area) { RawMoments rawMoments = new RawMoments(Order); rawMoments.Compute(image, area); this.Compute(rawMoments); }