void Moments(Image <Gray, byte> img, ref Double[] MomentSp, ref Double[] MomentCen, ref Double[] MomentNor) { Image <Gray, byte> imgA = new Image <Gray, byte>(img.Size); imgA = img.ThresholdBinary(new Gray(60), new Gray(255)); Contour <Point> contourA = imgA.FindContours(); MCvMoments momentsA = contourA.GetMoments(); for (int xOrder = 0; xOrder <= 3; xOrder++) { for (int yOrder = 0; yOrder <= 3; yOrder++) { if (xOrder + yOrder <= 3) { MomentSp[3 * xOrder + yOrder] = momentsA.GetSpatialMoment(xOrder, yOrder); MomentCen[3 * xOrder + yOrder] = momentsA.GetCentralMoment(xOrder, yOrder); MomentNor[3 * xOrder + yOrder] = momentsA.GetNormalizedCentralMoment(xOrder, yOrder); } } } /* for (int m = 0; m < 12; m++) * { * richTextBox4.AppendText("SP:"+MomentSp[m]+" CEN:"+MomentCen[m]+" Nor: "+MomentNor[m]+"\n"); * }*/ }
void Moments(Image <Gray, byte> img, ref Double[] MomentSp, ref Double[] MomentCen, ref Double[] MomentNor) { Image <Gray, byte> imgA = new Image <Gray, byte>(img.Size); imgA = img.ThresholdBinary(new Gray(60), new Gray(255)); Contour <Point> contourA = imgA.FindContours(); MCvMoments momentsA = contourA.GetMoments(); for (int xOrder = 0; xOrder <= 3; xOrder++) { for (int yOrder = 0; yOrder <= 3; yOrder++) { if (xOrder + yOrder <= 3) { MomentSp[3 * xOrder + yOrder] = momentsA.GetSpatialMoment(xOrder, yOrder); MomentCen[3 * xOrder + yOrder] = momentsA.GetCentralMoment(xOrder, yOrder); MomentNor[3 * xOrder + yOrder] = momentsA.GetNormalizedCentralMoment(xOrder, yOrder); } } } }