Example #1
0
        public static Matrix <T> Mean <T>(MatrixOp matrix)
            where T : struct
        {
            if (matrix == null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }

            matrix.ThrowIfDisposed();

            Matrix <T> .TryParse <T>(out var type);

            var ret = NativeMethods.matrix_mean(type.ToNativeMatrixElementType(),
                                                matrix.NativePtr,
                                                matrix.TemplateRows,
                                                matrix.TemplateColumns,
                                                matrix.ElementType,
                                                matrix.MatrixElementType,
                                                out var value);

            switch (ret)
            {
            case NativeMethods.ErrorType.MatrixElementTypeNotSupport:
                throw new ArgumentException($"{type} is not supported.");

            case NativeMethods.ErrorType.MatrixOpTypeNotSupport:
                throw new ArgumentException($"{matrix.ElementType} is not supported.");
            }

            return(new Matrix <T>(value, matrix.TemplateRows, matrix.TemplateColumns));
        }
Example #2
0
        public ImageWindow(MatrixOp matrix)
        {
            if (matrix == null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }

            matrix.ThrowIfDisposed(nameof(matrix));

            IntPtr ret;

            NativeMethods.ErrorType err;
            var tr  = matrix.TemplateRows;
            var tc  = matrix.TemplateColumns;
            var et  = matrix.ElementType;
            var ptr = matrix.NativePtr;

            if (tr == -1 && tc == -1)
            {
                err = NativeMethods.image_window_new_matrix_op1(et, matrix.Array2DType, ptr, out ret);
            }
            else
            {
                err = NativeMethods.image_window_new_matrix_op3(et, matrix.MatrixElementType, ptr, tr, tc, out ret);
            }

            switch (err)
            {
            case NativeMethods.ErrorType.MatrixOpTypeNotSupport:
                throw new ArgumentException($"{matrix.ElementType} is not supported.");
            }

            this.NativePtr = ret;
        }
Example #3
0
        public ImageWindow(MatrixOp matrix)
        {
            if (matrix == null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }

            matrix.ThrowIfDisposed(nameof(matrix));

            this.NativePtr = Native.image_window_new_matrix_op1(matrix.ElementType, matrix.Array2DType, matrix.NativePtr);
        }
Example #4
0
        public ImageWindow(MatrixOp matrix, string title)
        {
            if (matrix == null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }
            if (title == null)
            {
                throw new ArgumentNullException(nameof(title));
            }

            matrix.ThrowIfDisposed(nameof(matrix));

            var str = Encoding.UTF8.GetBytes(title);

            this.NativePtr = Native.image_window_new_matrix_op2(matrix.ElementType, matrix.Array2DType, matrix.NativePtr, str);
        }
Example #5
0
        public ImageWindow(MatrixOp matrix)
        {
            if (matrix == null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }

            matrix.ThrowIfDisposed(nameof(matrix));

            if (matrix.TemplateRows == -1 && matrix.TemplateColumns == -1)
            {
                this.NativePtr = Native.image_window_new_matrix_op1(matrix.ElementType, matrix.Array2DType, matrix.NativePtr);
            }
            else
            {
                this.NativePtr = Native.image_window_new_matrix_op3(matrix.ElementType, matrix.MatrixElementType, matrix.NativePtr, matrix.TemplateRows, matrix.TemplateColumns);
            }
        }
Example #6
0
        public ImageWindow(MatrixOp matrix, string title)
        {
            if (matrix == null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }
            if (title == null)
            {
                throw new ArgumentNullException(nameof(title));
            }

            matrix.ThrowIfDisposed(nameof(matrix));

            var str       = Dlib.Encoding.GetBytes(title);
            var strLength = str.Length;

            Array.Resize(ref str, strLength + 1);
            str[strLength] = (byte)'\0';

            IntPtr ret;

            NativeMethods.ErrorType err;
            var tr  = matrix.TemplateRows;
            var tc  = matrix.TemplateColumns;
            var et  = matrix.ElementType;
            var ptr = matrix.NativePtr;

            if (tr == -1 && matrix.TemplateColumns == -1)
            {
                err = NativeMethods.image_window_new_matrix_op2(et, matrix.Array2DType, ptr, str, out ret);
            }
            else
            {
                err = NativeMethods.image_window_new_matrix_op4(et, matrix.MatrixElementType, ptr, tr, tc, str, out ret);
            }

            switch (err)
            {
            case NativeMethods.ErrorType.MatrixOpTypeNotSupport:
                throw new ArgumentException($"{matrix.ElementType} is not supported.");
            }

            this.NativePtr = ret;
        }
Example #7
0
        public void SetImage(MatrixOp matrix)
        {
            this.ThrowIfDisposed();

            if (matrix == null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }

            matrix.ThrowIfDisposed();

            var ret = Native.image_window_set_image_matrix_op(this.NativePtr, matrix.ElementType, matrix.Array2DType, matrix.NativePtr);

            switch (ret)
            {
            case Dlib.Native.ErrorType.InputElementTypeNotSupport:
                throw new ArgumentException($"{matrix.ElementType} is not supported.");
            }
        }
Example #8
0
        public void SetImage(MatrixOp matrix)
        {
            this.ThrowIfDisposed();

            if (matrix == null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }

            matrix.ThrowIfDisposed();

            NativeMethods.ErrorType ret;
            switch (matrix.ElementType)
            {
            case NativeMethods.ElementType.OpHeatmap:
            case NativeMethods.ElementType.OpJet:
            case NativeMethods.ElementType.OpArray2DToMat:
            case NativeMethods.ElementType.OpTrans:
            case NativeMethods.ElementType.OpStdVectToMat:
                ret = NativeMethods.image_window_set_image_matrix_op_array2d(this.NativePtr, matrix.ElementType, matrix.Array2DType, matrix.NativePtr);
                break;

            case NativeMethods.ElementType.OpJoinRows:
                ret = NativeMethods.image_window_set_image_matrix_op_matrix(this.NativePtr, matrix.ElementType, matrix.MatrixElementType, matrix.NativePtr);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            switch (ret)
            {
            case NativeMethods.ErrorType.Array2DTypeTypeNotSupport:
                throw new ArgumentException($"{matrix.Array2DType} is not supported.");

            case NativeMethods.ErrorType.MatrixElementTypeNotSupport:
                throw new ArgumentException($"{matrix.MatrixElementType} is not supported.");

            case NativeMethods.ErrorType.MatrixOpTypeNotSupport:
                throw new ArgumentException($"{matrix.ElementType} is not supported.");
            }
        }
Example #9
0
        public static Point MaxPoint(MatrixOp matrix)
        {
            if (matrix == null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }

            matrix.ThrowIfDisposed();

            var type = matrix.Array2DType;
            var ret  = NativeMethods.matrix_max_point(type, matrix.NativePtr, out var point);

            switch (ret)
            {
            case NativeMethods.ErrorType.MatrixElementTypeNotSupport:
                throw new ArgumentException($"{type} is not supported.");
            }

            return(new Point(point));
        }
Example #10
0
        public ImageWindow(MatrixOp matrix, string title)
        {
            if (matrix == null)
            {
                throw new ArgumentNullException(nameof(matrix));
            }
            if (title == null)
            {
                throw new ArgumentNullException(nameof(title));
            }

            matrix.ThrowIfDisposed(nameof(matrix));

            var str = Dlib.Encoding.GetBytes(title);

            if (matrix.TemplateRows == -1 && matrix.TemplateColumns == -1)
            {
                this.NativePtr = NativeMethods.image_window_new_matrix_op2(matrix.ElementType, matrix.Array2DType, matrix.NativePtr, str);
            }
            else
            {
                this.NativePtr = NativeMethods.image_window_new_matrix_op4(matrix.ElementType, matrix.MatrixElementType, matrix.NativePtr, matrix.TemplateRows, matrix.TemplateColumns, str);
            }
        }