Exemplo n.º 1
0
        public static Matrix <TElement> Deserialize(ProxyDeserialize deserialize, uint templateRows = 0, uint templateColumns = 0)
        {
            if (!TryParse(typeof(TElement), out var type))
            {
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            }

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

            deserialize.ThrowIfDisposed();

            var ret = NativeMethods.matrix_deserialize_matrix_proxy(deserialize.NativePtr,
                                                                    type.ToNativeMatrixElementType(),
                                                                    (int)templateRows,
                                                                    (int)templateColumns,
                                                                    out var matrix,
                                                                    out var errorMessage);

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

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

            case NativeMethods.ErrorType.GeneralSerialization:
                throw new SerializationException(StringHelper.FromStdString(errorMessage, true));
            }

            return(new Matrix <TElement>(matrix, (int)templateRows, (int)templateColumns));
        }
Exemplo n.º 2
0
        public static Matrix <TElement> Deserialize(ProxyDeserialize deserialize, uint templateRows = 0, uint templateColumns = 0)
        {
            if (!TryParse(typeof(TElement), out var type))
            {
                throw new NotSupportedException($"{typeof(TElement).Name} does not support");
            }

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

            deserialize.ThrowIfDisposed();

            var ret = Dlib.Native.matrix_deserialize_matrix_proxy(deserialize.NativePtr,
                                                                  type.ToNativeMatrixElementType(),
                                                                  (int)templateRows,
                                                                  (int)templateColumns,
                                                                  out var matrix);

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

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

            return(new Matrix <TElement>(matrix, (int)templateRows, (int)templateColumns));
        }
Exemplo n.º 3
0
        public static ShapePredictor Deserialize(ProxyDeserialize deserialize)
        {
            if (deserialize == null)
            {
                throw new ArgumentNullException(nameof(deserialize));
            }

            deserialize.ThrowIfDisposed();

            var ret = NativeMethods.deserialize_shape_predictor_proxy(deserialize.NativePtr);

            return(new ShapePredictor(ret));
        }
Exemplo n.º 4
0
        public static ShapePredictor Deserialize(ProxyDeserialize deserialize)
        {
            if (deserialize == null)
            {
                throw new ArgumentNullException(nameof(deserialize));
            }

            deserialize.ThrowIfDisposed();

            var ret = NativeMethods.deserialize_shape_predictor_proxy(deserialize.NativePtr,
                                                                      out var predictor,
                                                                      out var errorMessage);

            switch (ret)
            {
            case NativeMethods.ErrorType.GeneralSerialization:
                throw new SerializationException(StringHelper.FromStdString(errorMessage, true));
            }

            return(new ShapePredictor(predictor));
        }