Ejemplo n.º 1
0
        private Array(bool specifySize, uint size)
        {
            if (!SupportItemTypes.TryGetValue(typeof(T), out this._ItemType))
            {
                throw new NotSupportedException($"{typeof(T).Name} does not support");
            }

            switch (this._ItemType)
            {
            case ItemTypes.PixelType:
            {
                if (!SupportArray2DElementTypes.TryGetValue(typeof(T), out this._ArrayElementType))
                {
                    throw new NotSupportedException($"{typeof(T).Name} does not support");
                }

                var type = this._ArrayElementType.ToNativeArray2DType();
                this.NativePtr = specifySize ? NativeMethods.array_new1(type, size) : NativeMethods.array_new(type);
            }
            break;

            case ItemTypes.Array2D:
            {
                var types = typeof(T).GenericTypeArguments;
                if (types.Length != 1)
                {
                    throw new NotSupportedException($"{typeof(T).Name} does not support");
                }
                if (!SupportArray2DElementTypes.TryGetValue(types[0], out this._ArrayElementType))
                {
                    throw new NotSupportedException($"{types[0].Name} does not support");
                }

                var type = this._ArrayElementType.ToNativeArray2DType();
                this.NativePtr    = specifySize ? NativeMethods.array_array2d_new1(type, size) : NativeMethods.array_array2d_new(type);
                this._Array2DType = this._ArrayElementType.ToNativeArray2DType();
            }
            break;

            case ItemTypes.Matrix:
            {
                var types = typeof(T).GenericTypeArguments;
                if (types.Length != 1)
                {
                    throw new NotSupportedException($"{typeof(T).Name} does not support");
                }
                if (!SupportMatrixElementTypes.TryGetValue(types[0], out this._MatrixElementType))
                {
                    throw new NotSupportedException($"{typeof(T).Name} does not support");
                }

                var type = this._MatrixElementType.ToNativeMatrixElementType();
                this.NativePtr = specifySize ? NativeMethods.array_matrix_new1(type, size) : NativeMethods.array_matrix_new(type);
            }
            break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Ejemplo n.º 2
0
        internal Array2D(IntPtr ptr, ImageTypes type, bool isEnabledDispose = true) :
            base(isEnabledDispose)
        {
            if (ptr == IntPtr.Zero)
            {
                throw new ArgumentException("Can not pass IntPtr.Zero", nameof(ptr));
            }

            this.NativePtr    = ptr;
            this._Array2DType = type.ToNativeArray2DType();

            this.ImageType = type;
        }
Ejemplo n.º 3
0
        public Array2D(int rows, int columns)
        {
            if (!SupportTypes.TryGetValue(typeof(TElement), out var type))
            {
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            }

            this._Array2DType = type.ToNativeArray2DType();

            this.NativePtr = NativeMethods.array2d_new1(this._Array2DType, rows, columns);
            if (this.NativePtr == IntPtr.Zero)
            {
                throw new ArgumentException($"{type} is not supported.");
            }

            this.ImageType = type;
        }
Ejemplo n.º 4
0
        private object GetArray2DItem(Array2DType type, uint index)
        {
            var err = NativeMethods.array_array2d_getitem(type,
                                                          this.NativePtr, index,
                                                          out var array);

            switch (type)
            {
            case Array2DType.UInt8:
                return(new Array2D <byte>(array, ImageTypes.UInt8, false));

            case Array2DType.UInt16:
                return(new Array2D <ushort>(array, ImageTypes.UInt16, false));

            case Array2DType.UInt32:
                return(new Array2D <uint>(array, ImageTypes.UInt32, false));

            case Array2DType.Int8:
                return(new Array2D <sbyte>(array, ImageTypes.Int8, false));

            case Array2DType.Int16:
                return(new Array2D <short>(array, ImageTypes.Int16, false));

            case Array2DType.Int32:
                return(new Array2D <int>(array, ImageTypes.Int32, false));

            case Array2DType.Float:
                return(new Array2D <float>(array, ImageTypes.Float, false));

            case Array2DType.Double:
                return(new Array2D <double>(array, ImageTypes.Double, false));

            case Array2DType.RgbPixel:
                return(new Array2D <RgbPixel>(array, ImageTypes.RgbPixel, false));

            case Array2DType.RgbAlphaPixel:
                return(new Array2D <RgbAlphaPixel>(array, ImageTypes.RgbAlphaPixel, false));

            case Array2DType.HsiPixel:
                return(new Array2D <HsiPixel>(array, ImageTypes.HsiPixel, false));

            default:
                throw new ArgumentOutOfRangeException(nameof(type), type, null);
            }
        }
Ejemplo n.º 5
0
 public static extern ErrorType correlation_tracker_update2(IntPtr tracker,
                                                            Array2DType imgType,
                                                            IntPtr img,
                                                            out double confident);
Ejemplo n.º 6
0
 public static extern ErrorType correlation_tracker_start_track(IntPtr tracker,
                                                                Array2DType imgType,
                                                                IntPtr img,
                                                                IntPtr p);
Ejemplo n.º 7
0
 private void PushBackArray2DItem(Array2DType type, IDlibObject item)
 {
     item.ThrowIfDisposed();
     NativeMethods.array_array2d_pushback(type, this.NativePtr, item.NativePtr);
 }