Пример #1
0
        public static void DrawRectangle(Array2DBase image, Rectangle rect, HsiPixel color, uint thickness = 1)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            if (rect == null)
            {
                throw new ArgumentNullException(nameof(rect));
            }

            image.ThrowIfDisposed();
            rect.ThrowIfDisposed();

            var ret = Native.draw_rectangle(
                Native.Array2DType.HsiPixel,
                image.NativePtr,
                rect.NativePtr,
                ref color,
                thickness);

            switch (ret)
            {
            case Native.ErrorType.ArrayTypeNotSupport:
                throw new ArgumentException($"{color} is not supported.");
            }
        }
Пример #2
0
        /// <summary>
        /// Adds the given overlay rectangle into this object such that it will be displayed.
        /// </summary>
        /// <param name="rect">A <see cref="DRectangle"/> structure that represents the rectangle to be displayed.</param>
        /// <param name="color">A <see cref="HsiPixel"/> value that represents a color.</param>
        /// <exception cref="ObjectDisposedException"><see cref="ImageWindow"/> is disposed.</exception>
        public void AddOverlay(DRectangle rect, HsiPixel color)
        {
            this.ThrowIfDisposed();

            using (var native = rect.ToNative())
                NativeMethods.image_window_add_overlay3(this.NativePtr, native.NativePtr, NativeMethods.Array2DType.HsiPixel, ref color);
        }
Пример #3
0
        public static void DrawLine(Array2D <HsiPixel> image, Point p1, Point p2, HsiPixel color)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            if (p1 == null)
            {
                throw new ArgumentNullException(nameof(p1));
            }
            if (p2 == null)
            {
                throw new ArgumentNullException(nameof(p2));
            }

            image.ThrowIfDisposed();

            using (var np1 = p1.ToNative())
                using (var np2 = p2.ToNative())
                {
                    var ret = NativeMethods.draw_line(NativeMethods.Array2DType.HsiPixel,
                                                      image.NativePtr,
                                                      np1.NativePtr,
                                                      np2.NativePtr,
                                                      ref color);
                    switch (ret)
                    {
                    case NativeMethods.ErrorType.Array2DTypeTypeNotSupport:
                        throw new ArgumentException($"{color} is not supported.");
                    }
                }
        }
Пример #4
0
        public static void DrawLine(Array2DBase image, Point p1, Point p2, HsiPixel color)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            if (p1 == null)
            {
                throw new ArgumentNullException(nameof(p1));
            }
            if (p2 == null)
            {
                throw new ArgumentNullException(nameof(p2));
            }

            image.ThrowIfDisposed();
            p1.ThrowIfDisposed();
            p2.ThrowIfDisposed();
            var ret = Native.draw_line(
                Native.Array2DType.HsiPixel,
                image.NativePtr,
                p1.NativePtr,
                p2.NativePtr,
                ref color);

            switch (ret)
            {
            case Native.ErrorType.ArrayTypeNotSupport:
                throw new ArgumentException($"{color} is not supported.");
            }
        }
Пример #5
0
        public void AddOverlay(IEnumerable <Rectangle> rects, HsiPixel color)
        {
            this.ThrowIfDisposed();

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

            using (var vector = new StdVector <Rectangle>(rects))
                NativeMethods.image_window_add_overlay2(this.NativePtr, vector.NativePtr, NativeMethods.Array2DType.HsiPixel, ref color);
        }
Пример #6
0
        public void AddOverlay(DRectangle rect, HsiPixel color)
        {
            this.ThrowIfDisposed();

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

            rect.ThrowIfDisposed();

            Native.image_window_add_overlay3(this.NativePtr, rect.NativePtr, Dlib.Native.Array2DType.HsiPixel, ref color);
        }
Пример #7
0
        public void AddOverlay(Rectangle rect, HsiPixel color, string str)
        {
            if (str == null)
            {
                throw new ArgumentNullException(nameof(str));
            }

            this.ThrowIfDisposed();

            using (var native = rect.ToNative())
                using (var pStr = new StdString(str))
                    NativeMethods.image_window_add_overlay6(this.NativePtr, native.NativePtr, NativeMethods.Array2DType.HsiPixel, ref color, pStr.NativePtr);
        }
Пример #8
0
        public void AddOverlay(IEnumerable <Vector <double> > points, HsiPixel color)
        {
            this.ThrowIfDisposed();

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

            points.ThrowIfDisposed();

            using (var vector = new StdVector <Vector <double> >(points))
                NativeMethods.perspective_window_add_overlay3(this.NativePtr, vector.NativePtr, NativeMethods.Array2DType.HsiPixel, ref color);
        }
Пример #9
0
        public static void AssignAllPpixels(Array2D <HsiPixel> dest, HsiPixel pixel)
        {
            if (dest == null)
            {
                throw new ArgumentNullException(nameof(dest));
            }

            dest.ThrowIfDisposed(nameof(dest));

            var outType = dest.ImageType.ToNativeArray2DType();
            var ret     = Native.assign_all_pixels(outType, dest.NativePtr, Native.Array2DType.HsiPixel, ref pixel);

            switch (ret)
            {
            case Native.ErrorType.Array2DTypeTypeNotSupport:
                throw new ArgumentException("Output or input type is not supported.");
            }
        }
Пример #10
0
        public void AddOverlay(Vector <double> p1, Vector <double> p2, HsiPixel color)
        {
            this.ThrowIfDisposed();

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

            p1.ThrowIfDisposed();
            p2.ThrowIfDisposed();

            NativeMethods.perspective_window_add_overlay(this.NativePtr, p1.NativePtr, p2.NativePtr, NativeMethods.Array2DType.HsiPixel, ref color);
        }
Пример #11
0
        public static void FillRect(Array2D <HsiPixel> image, Rectangle rect, HsiPixel color)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            image.ThrowIfDisposed();

            using (var native = rect.ToNative())
            {
                var ret = NativeMethods.fill_rect(NativeMethods.Array2DType.HsiPixel,
                                                  image.NativePtr,
                                                  native.NativePtr,
                                                  ref color);
                switch (ret)
                {
                case NativeMethods.ErrorType.Array2DTypeTypeNotSupport:
                    throw new ArgumentException($"{color} is not supported.");
                }
            }
        }
Пример #12
0
 public static extern void array2d_set_row_column_hsi_pixel(IntPtr row, int column, HsiPixel value);
Пример #13
0
 public static extern ErrorType draw_rectangle_matrix(MatrixElementType elementType, IntPtr matrix, IntPtr rect, ref HsiPixel color, uint thickness);
Пример #14
0
 public static extern void assign_pixel_rgbalpha_hsi(ref RgbAlphaPixel dest, ref HsiPixel src);
Пример #15
0
 public static extern ErrorType draw_line(Array2DType pixelType, IntPtr image, IntPtr p1, IntPtr p2, ref HsiPixel color);
Пример #16
0
 public static extern NativeMethods.ErrorType image_window_add_overlay2(IntPtr window, IntPtr vectorOfRect, NativeMethods.Array2DType type, ref HsiPixel color);
Пример #17
0
 public static extern ErrorType draw_line_canvas_infinity(IntPtr canvas, IntPtr p1, IntPtr p2, Array2DType pixelType, ref HsiPixel color);
Пример #18
0
 public static extern ErrorType fill_rect_matrix(MatrixElementType elementType, IntPtr matrix, IntPtr rect, ref HsiPixel color);
Пример #19
0
 public static extern ErrorType draw_line_matrix(MatrixElementType elementType, IntPtr matrix, IntPtr p1, IntPtr p2, ref HsiPixel color);
Пример #20
0
 public static extern ErrorType perspective_window_add_overlay3(IntPtr window, IntPtr vector, Array2DType type, ref HsiPixel color);
Пример #21
0
 public static void AssignPixel(ref RgbAlphaPixel dest, HsiPixel src)
 {
     NativeMethods.assign_pixel_rgbalpha_hsi(ref dest, ref src);
 }
Пример #22
0
 public static extern ErrorType draw_rectangle(Array2DType pixelType, IntPtr image, IntPtr rect, ref HsiPixel color, uint thickness);
Пример #23
0
 public static extern void matrix_operator_get_row_column_hsi_pixel(IntPtr matrix, int row, int column, out HsiPixel ret);
Пример #24
0
 public static extern ErrorType fill_rect(Array2DType pixelType, IntPtr image, IntPtr rect, ref HsiPixel color);
Пример #25
0
 public static extern void matrix_operator_set_row_column_hsi_pixel(IntPtr matrix, int row, int column, HsiPixel value);
Пример #26
0
 public static extern IntPtr perspective_window_overlay_dot_new2(IntPtr v, NativeMethods.Array2DType type, ref HsiPixel color);
Пример #27
0
 public static extern ErrorType draw_rectangle_canvas(IntPtr canvas, IntPtr rect, IntPtr area, Array2DType pixelType, ref HsiPixel color);
Пример #28
0
 public static extern void assign_pixel_rgb_hsi(ref RgbPixel dest, ref HsiPixel src);
Пример #29
0
        public TElement[] ToArray()
        {
            this.ThrowIfDisposed();

            TElement[] result;
            NativeMethods.ErrorType err;

            var templateRows    = this.TemplateRows;
            var templateColumns = this.TemplateColumns;

            switch (this._MatrixElementTypes)
            {
            case MatrixElementTypes.UInt8:
                unsafe
                {
                    var row    = this.Rows;
                    var column = this.Columns;

                    var array = new byte[row * column];
                    fixed(byte *dst = &array[0])
                    {
                        var src  = this.NativePtr;
                        var type = this._ElementType;

                        err = NativeMethods.extensions_matrix_to_array(src, type, templateRows, templateColumns, (IntPtr)dst);
                    }

                    result = array as TElement[];
                }
                break;

            case MatrixElementTypes.UInt16:
                unsafe
                {
                    var row    = this.Rows;
                    var column = this.Columns;

                    var array = new ushort[row * column];
                    fixed(ushort *dst = &array[0])
                    {
                        var src  = this.NativePtr;
                        var type = this._ElementType;

                        err = NativeMethods.extensions_matrix_to_array(src, type, templateRows, templateColumns, (IntPtr)dst);
                    }

                    result = array as TElement[];
                }
                break;

            case MatrixElementTypes.UInt32:
                unsafe
                {
                    var row    = this.Rows;
                    var column = this.Columns;

                    var array = new uint[row * column];
                    fixed(uint *dst = &array[0])
                    {
                        var src  = this.NativePtr;
                        var type = this._ElementType;

                        err = NativeMethods.extensions_matrix_to_array(src, type, templateRows, templateColumns, (IntPtr)dst);
                    }

                    result = array as TElement[];
                }
                break;

            case MatrixElementTypes.Int8:
                unsafe
                {
                    var row    = this.Rows;
                    var column = this.Columns;

                    var array = new sbyte[row * column];
                    fixed(sbyte *dst = &array[0])
                    {
                        var src  = this.NativePtr;
                        var type = this._ElementType;

                        err = NativeMethods.extensions_matrix_to_array(src, type, templateRows, templateColumns, (IntPtr)dst);
                    }

                    result = array as TElement[];
                }
                break;

            case MatrixElementTypes.Int16:
                unsafe
                {
                    var row    = this.Rows;
                    var column = this.Columns;

                    var array = new short[row * column];
                    fixed(short *dst = &array[0])
                    {
                        var src  = this.NativePtr;
                        var type = this._ElementType;

                        err = NativeMethods.extensions_matrix_to_array(src, type, templateRows, templateColumns, (IntPtr)dst);
                    }

                    result = array as TElement[];
                }
                break;

            case MatrixElementTypes.Int32:
                unsafe
                {
                    var row    = this.Rows;
                    var column = this.Columns;

                    var array = new int[row * column];
                    fixed(int *dst = &array[0])
                    {
                        var src  = this.NativePtr;
                        var type = this._ElementType;

                        err = NativeMethods.extensions_matrix_to_array(src, type, templateRows, templateColumns, (IntPtr)dst);
                    }

                    result = array as TElement[];
                }
                break;

            case MatrixElementTypes.Float:
                unsafe
                {
                    var row    = this.Rows;
                    var column = this.Columns;

                    var array = new float[row * column];
                    fixed(float *dst = &array[0])
                    {
                        var src  = this.NativePtr;
                        var type = this._ElementType;

                        err = NativeMethods.extensions_matrix_to_array(src, type, templateRows, templateColumns, (IntPtr)dst);
                    }

                    result = array as TElement[];
                }
                break;

            case MatrixElementTypes.Double:
                unsafe
                {
                    var row    = this.Rows;
                    var column = this.Columns;

                    var array = new double[row * column];
                    fixed(double *dst = &array[0])
                    {
                        var src  = this.NativePtr;
                        var type = this._ElementType;

                        err = NativeMethods.extensions_matrix_to_array(src, type, templateRows, templateColumns, (IntPtr)dst);
                    }

                    result = array as TElement[];
                }
                break;

            case MatrixElementTypes.RgbPixel:
                unsafe
                {
                    var row    = this.Rows;
                    var column = this.Columns;

                    var array = new RgbPixel[row * column];
                    fixed(RgbPixel *dst = &array[0])
                    {
                        var src  = this.NativePtr;
                        var type = this._ElementType;

                        err = NativeMethods.extensions_matrix_to_array(src, type, templateRows, templateColumns, (IntPtr)dst);
                    }

                    result = array as TElement[];
                }
                break;

            case MatrixElementTypes.BgrPixel:
                unsafe
                {
                    var row    = this.Rows;
                    var column = this.Columns;

                    var array = new BgrPixel[row * column];
                    fixed(BgrPixel *dst = &array[0])
                    {
                        var src  = this.NativePtr;
                        var type = this._ElementType;

                        err = NativeMethods.extensions_matrix_to_array(src, type, templateRows, templateColumns, (IntPtr)dst);
                    }

                    result = array as TElement[];
                }
                break;

            case MatrixElementTypes.RgbAlphaPixel:
                unsafe
                {
                    var row    = this.Rows;
                    var column = this.Columns;

                    var array = new RgbAlphaPixel[row * column];
                    fixed(RgbAlphaPixel *dst = &array[0])
                    {
                        var src  = this.NativePtr;
                        var type = this._ElementType;

                        err = NativeMethods.extensions_matrix_to_array(src, type, templateRows, templateColumns, (IntPtr)dst);
                    }

                    result = array as TElement[];
                }
                break;

            case MatrixElementTypes.HsiPixel:
                unsafe
                {
                    var row    = this.Rows;
                    var column = this.Columns;

                    var array = new HsiPixel[row * column];
                    fixed(HsiPixel *dst = &array[0])
                    {
                        var src  = this.NativePtr;
                        var type = this._ElementType;

                        err = NativeMethods.extensions_matrix_to_array(src, type, templateRows, templateColumns, (IntPtr)dst);
                    }

                    result = array as TElement[];
                }
                break;

            case MatrixElementTypes.LabPixel:
                unsafe
                {
                    var row    = this.Rows;
                    var column = this.Columns;

                    var array = new LabPixel[row * column];
                    fixed(LabPixel *dst = &array[0])
                    {
                        var src  = this.NativePtr;
                        var type = this._ElementType;

                        err = NativeMethods.extensions_matrix_to_array(src, type, templateRows, templateColumns, (IntPtr)dst);
                    }

                    result = array as TElement[];
                }
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

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

            case NativeMethods.ErrorType.MatrixElementTemplateSizeNotSupport:
                throw new ArgumentException($"{nameof(this.TemplateColumns)} or {nameof(this.TemplateRows)} is not supported.");
            }

            return(result);
        }
Пример #30
0
 public static extern ErrorType assign_all_pixels(Array2DType out_type, IntPtr out_img, Array2DType in_type, ref HsiPixel color);