Esempio n. 1
0
        /// <summary>
        /// Indicates whether the current object is equal to another object of the same type.
        /// </summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        /// true if the current object is equal to the <paramref name="other" /> parameter; otherwise, false.
        /// </returns>
        public bool Equals(UMat other)
        {
            if (!(Size.Equals(other.Size) && NumberOfChannels == other.NumberOfChannels && Depth == other.Depth))
            {
                return(false);
            }

            using (UMat cmpResult = new UMat())
            {
                CvInvoke.Compare(this, other, cmpResult, CmpType.NotEqual);
                using (UMat reshaped = cmpResult.Reshape(1))
                    return(CvInvoke.CountNonZero(reshaped) == 0);
            }
        }
Esempio n. 2
0
        /// <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();
                        }
                    }
                }
            }
        }