/// <summary> /// Return true if every element of this matrix equals elements in <paramref name="mat2"/> /// </summary> /// <param name="mat2">The other matrix to compare with</param> /// <returns>true if every element of this matrix equals elements in <paramref name="mat2"/></returns> public bool Equals(Matrix <TDepth> mat2) { if (!Size.Equals(mat2.Size)) { return(false); } int numberOfChannels = NumberOfChannels; if (numberOfChannels != mat2.NumberOfChannels) { return(false); } using (Matrix <TDepth> xor = new Matrix <TDepth>(Rows, Cols, numberOfChannels)) { CvInvoke.BitwiseXor(this, mat2, xor, null); if (numberOfChannels == 1) { return(CvInvoke.CountNonZero(xor) == 0); } else { //comapre channel by channel Matrix <TDepth>[] channels = xor.Split(); try { for (int i = 0; i < numberOfChannels; i++) { if (CvInvoke.CountNonZero(channels[i]) != 0) { return(false); } } return(true); } finally { foreach (Matrix <TDepth> channel in channels) { channel.Dispose(); } } } } }
/// <summary> /// Check if the two MatND are equal /// </summary> /// <param name="other">The other MatND to compares to</param> /// <returns>True if the two MatND equals</returns> public bool Equals(MatND <TDepth> other) { #region check if the two MatND has equal dimension int[] dim1 = GetDimension(); int[] dim2 = other.GetDimension(); if (dim1.Length != dim2.Length) { return(false); } for (int i = 0; i < dim1.Length; i++) { if (dim1[i] != dim2[i]) { return(false); } } #endregion using (MatND <TDepth> diff = new MatND <TDepth>(dim1)) { CvInvoke.BitwiseXor(this, other, diff, null); return(Array.TrueForAll(diff.Bytes, delegate(Byte b) { return b == 0; })); } }