Пример #1
0
        /// <summary>
        /// 参照カウンタのポインタが null ではない場合に CvMat あるいは CvMatND のデータの参照カウンタをデクリメントし,さらにカウンタが 0 になった場合にはデータを解放する.
        /// </summary>
        /// <param name="arr">配列ヘッダ</param>
#else
        /// <summary>
        /// Decrements array data reference counter.
        /// </summary>
        /// <param name="arr">Input array. </param>
#endif
        public static void DecRefData(CvArr arr)
        {
            if (arr == null)
            {
                throw new ArgumentNullException(nameof(arr));
            }
            unsafe
            {
                if (arr is CvMat)
                {
                    CvMat mat = (CvMat)arr;
                    mat.Data = IntPtr.Zero;
                    if (mat.RefCount != IntPtr.Zero && --*(int *)mat.RefCount == 0)
                    {
                        NativeMethods.cvFree_(mat.RefCount);
                    }
                    mat.RefCount = IntPtr.Zero;
                }
                else if (arr is CvMatND)
                {
                    CvMatND mat = (CvMatND)arr;
                    mat.Data = IntPtr.Zero;
                    if (mat.RefCount != IntPtr.Zero && --*(int *)mat.RefCount == 0)
                    {
                        NativeMethods.cvFree_(mat.RefCount);
                    }
                    mat.RefCount = IntPtr.Zero;
                }
            }
            KeepAlive(arr);
        }
Пример #2
0
        /// <summary>
        /// 行列とスカラーのxor演算子。cvXorSにより求める。
        /// </summary>
        /// <param name="a">行列</param>
        /// <param name="b">スカラー</param>
        /// <returns></returns>
#else
        /// <summary>
        /// Bitwise XOR operator (cvXorS)
        /// </summary>
        /// <param name="a">matrix</param>
        /// <param name="b">scalar</param>
        /// <returns></returns>
#endif
        public static CvMatND operator ^(CvMatND a, CvScalar b)
        {
            if (a == null)
            {
                throw new ArgumentNullException("a");
            }
            CvMatND result = a.Clone();

            Cv.XorS(a, b, result);
            return(result);
        }
Пример #3
0
        /// <summary>
        /// 行列とスカラーの乗算演算子。aの要素ごとにbをかけた結果をcvAddWeightedにより求める。
        /// </summary>
        /// <param name="a">行列</param>
        /// <param name="b">スカラー</param>
        /// <returns></returns>
#else
        /// <summary>
        /// Multiplicative operator (cvAddWeighted)
        /// </summary>
        /// <param name="a">matrix</param>
        /// <param name="b">scalar</param>
        /// <returns></returns>
#endif
        public static CvMatND operator *(CvMatND a, Double b)
        {
            if (a == null)
            {
                throw new ArgumentNullException("a");
            }
            CvMatND result = a.Clone();

            Cv.AddWeighted(a, b, a, 0, 0, result);
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 行列の単項not演算子
        /// </summary>
        /// <param name="a">行列</param>
        /// <returns></returns>
#else
        /// <summary>
        /// Logical nagation operator
        /// </summary>
        /// <param name="a">matrix</param>
        /// <returns></returns>
#endif
        public static CvMatND operator ~(CvMatND a)
        {
            if (a == null)
            {
                throw new ArgumentNullException("a");
            }
            CvMatND result = a.Clone();

            Cv.Not(a, result);
            return(result);
        }
Пример #5
0
        /// <summary>
        /// 指定した2つの行列のデータタイプが等しければtrueを返す
        /// </summary>
        /// <param name="mat1">1つ目の入力行列</param>
        /// <param name="mat2">2つ目の入力行列</param>
        /// <returns></returns>
#else
        /// <summary>
        ///
        /// </summary>
        /// <param name="mat1"></param>
        /// <param name="mat2"></param>
        /// <returns></returns>
#endif
        public static bool ARE_TYPES_EQ(CvMatND mat1, CvMatND mat2)
        {
            if (mat1 == null)
            {
                throw new ArgumentNullException("mat1");
            }
            if (mat2 == null)
            {
                throw new ArgumentNullException("mat2");
            }
            return(((mat1.Type ^ mat2.Type) & CvConst.CV_MAT_TYPE_MASK) == 0);
        }
Пример #6
0
        /// <summary>
        /// 行列と行列のor演算子。cvOrにより求める。
        /// </summary>
        /// <param name="a">行列</param>
        /// <param name="b">行列</param>
        /// <returns></returns>
#else
        /// <summary>
        /// Bitwise OR operator (cvOr)
        /// </summary>
        /// <param name="a">matrix</param>
        /// <param name="b">matrix</param>
        /// <returns></returns>
#endif
        public static CvMatND operator |(CvMatND a, CvMatND b)
        {
            if (a == null)
            {
                throw new ArgumentNullException("a");
            }
            if (b == null)
            {
                throw new ArgumentNullException("b");
            }
            CvMatND result = a.Clone();

            Cv.Or(a, b, result);
            return(result);
        }
Пример #7
0
        /// <summary>
        /// 行列とスカラーの除算演算子。aの要素ごとにbで割った結果をcvAddWeightedにより求める。
        /// </summary>
        /// <param name="a">行列</param>
        /// <param name="b">スカラー</param>
        /// <returns></returns>
#else
        /// <summary>
        /// Division operator (cvAddWeighted)
        /// </summary>
        /// <param name="a">matrix</param>
        /// <param name="b">scalar</param>
        /// <returns></returns>
#endif
        public static CvMatND operator /(CvMatND a, double b)
        {
            if (a == null)
            {
                throw new ArgumentNullException("a");
            }
            if (b == 0)
            {
                throw new DivideByZeroException();
            }

            CvMatND result = a.Clone();

            Cv.AddWeighted(a, 1.0 / b, a, 0, 0, result);
            return(result);
        }