Exemplo n.º 1
0
 public static bool imwrite(string path, Mat img)
 {
     if (path == null || img == null)
     {
         return(false);
     }
     return(0 == NativeInvoker.coreCvImwrite(path, img.MatObj) ? false : true);
 }
Exemplo n.º 2
0
 public void convertTo(Mat dst, int type, double alpha = 1.0, double beta = 0.0)
 {
     if (dst == null || !dst.Valid)
     {
         return;
     }
     NativeInvoker.coreCvConvertMat(MatObj, dst.MatObj, type, alpha, beta);
 }
Exemplo n.º 3
0
        public Mat roi(Rect <int> r)
        {
            Mat ret = new Mat();

            if (!ret.Valid)
            {
                return(null);
            }
            NativeInvoker.coreCvMatRoi(MatObj, r.x, r.y, r.width, r.height, ret.MatObj);
            return(ret);
        }
Exemplo n.º 4
0
        public Mat clone()
        {
            Mat ret = new Mat();

            if (!ret.Valid)
            {
                return(null);
            }
            NativeInvoker.coreCvCloneMat(MatObj, ret.MatObj);
            return(ret);
        }
Exemplo n.º 5
0
        public static Mat imread(string path, LOAD_IMAGE flag = LOAD_IMAGE.COLOR)
        {
            var ret = new Mat();

            if (path == null)
            {
                return(ret);
            }
            NativeInvoker.coreCvImread(path, (int)flag, ret.MatObj);             // check enum cast work
            return(ret);
        }
Exemplo n.º 6
0
        public static void merge(List <Mat> src, Mat dst)
        {
            if (src == null || src.Count == 0)
            {
                return;
            }

            if (!src[0].Valid || src[0].IsEmpty)
            {
                return;
            }

            if (!dst.Valid)
            {
                return;
            }

            int rows = src[0].Rows, cols = src[0].Cols;

            int dstChannels = src[0].Channels;
            int n           = src.Count;   // src[i] may have more than 1 channel
            var srcPtrs     = new IntPtr[n];

            srcPtrs[0] = src[0].MatObj;

            for (int i = 1; i < n; i++)             // check valid, size, and sumation over channel
            {
                if (src[i].Valid && src[i].Rows == rows && src[i].Cols == cols)
                {
                    dstChannels += src[i].Channels;
                    srcPtrs[i]   = src[i].MatObj;
                }
                else
                {
                    return;
                }
            }

            if (dstChannels > Mat.CV_CN_MAX)             // exceed max channels support
            {
                return;
            }

            var srcPtrMat = new Mat(1, n * Marshal.SizeOf <IntPtr>(), Mat.makeType(1, Mat.MatDepth.CV_8U));

            if (!srcPtrMat.Valid)             // alloc unmanaged memory
            {
                return;
            }
            Marshal.Copy(srcPtrs, 0, srcPtrMat.Data, n);
            NativeInvoker.coreCvMerge(srcPtrMat.Data, n, dst.MatObj);
        }
Exemplo n.º 7
0
        public static void split(Mat src, List <Mat> dst)
        {
            if (!src.Valid || src.IsEmpty)
            {
                return;
            }
            int channel = src.Channels;

            if (dst == null)
            {
                dst = new List <Mat>();
            }
            if (channel > dst.Count)
            {
                while (dst.Count < channel)
                {
                    dst.Add(new Mat());
                }
            }
            else if (channel < dst.Count)
            {
                dst.RemoveRange(channel, dst.Count - channel);
            }

            var dstPtrs = new IntPtr[channel];

            for (int i = 0; i < channel; i++)
            {
                if (dst[i].Valid)
                {
                    dstPtrs[i] = dst[i].MatObj;
                }
                else
                {
                    return;                     // check every mat in dst is valid
                }
            }
            var dstPtrMat = new Mat(1, channel * Marshal.SizeOf <IntPtr>(), Mat.makeType(1, Mat.MatDepth.CV_8U));
            if (!dstPtrMat.Valid)             // alloc unmanaged memory
            {
                return;
            }
            Marshal.Copy(dstPtrs, 0, dstPtrMat.Data, channel);
            NativeInvoker.coreCvSplit(src.MatObj, dstPtrMat.Data, channel);
        }
Exemplo n.º 8
0
        public static void warpAffine(Mat src, Mat dst, System.Numerics.Matrix3x2 trans, Size dSize,
                                      Interpolation inter   = Interpolation.INTER_LINEAR, bool inverseMap      = false,
                                      BorderMode borderMode = BorderMode.BORDER_CONSTANT, double[] borderValue = null)
        {
            Mat    transMat       = trans;
            int    flags          = inverseMap ? ((int)InverseMap.WARP_INVERSE_MAP | (int)inter) : (int)inter;
            Mat    matBorderValue = null;
            IntPtr ptrBorderValue = IntPtr.Zero;

            if (borderMode == BorderMode.BORDER_CONSTANT && borderValue != null && borderValue.Length > 0)
            {
                matBorderValue = new Mat(1, borderValue.Length, Mat.makeType(1, Mat.MatDepth.CV_64F));
                if (matBorderValue.Valid && matBorderValue.copyAll(borderValue, 0, borderValue.Length))
                {
                    ptrBorderValue = matBorderValue.Data;
                }
            }
            NativeInvoker.coreCvWarpAffine(src.MatObj, dst.MatObj, transMat.MatObj, (int)dSize.w, (int)dSize.h,
                                           flags, (int)borderMode, ptrBorderValue);
        }
Exemplo n.º 9
0
        internal static void Initialize(IntPtr ptrClient, bool isWinDbg)
        {
            // On our first call to the API:
            //   1. Store a copy of IDebugClient in DebugClient.
            //   2. Replace Console's output stream to be the debugger window.
            //   3. Create an instance of DataTarget using the IDebugClient.
            if (DataTarget == null)
            {
                if (!isWinDbg)
                {
                    DebugClient = NativeInvoker.GetInstance <ILLDBDebugClient>(ptrClient, vtable);

                    var linuxFunctionsType = Type.GetType("Microsoft.Diagnostics.Runtime.LinuxFunctions, Microsoft.Diagnostics.Runtime");

                    var field = typeof(DataTarget).GetField("<PlatformFunctions>k__BackingField", BindingFlags.Static | BindingFlags.NonPublic);

                    field.SetValue(null, Activator.CreateInstance(linuxFunctionsType));

                    Console.SetOut(new StripDmlWriter(Console.Out));
                }
                else
                {
                    DebugClient = (IDebugClient)Marshal.GetUniqueObjectForIUnknown(ptrClient);

                    var stream = new StreamWriter(new DbgEngStream(DebugClient))
                    {
                        AutoFlush = true
                    };
                    Console.SetOut(stream);
                }

                DataTarget = DataTarget.CreateFromDbgEng(ptrClient);
            }

            // If our ClrRuntime instance is null, it means that this is our first call, or
            // that the dac wasn't loaded on any previous call.
            if (Runtime == null)
            {
                Runtime = DataTarget.ClrVersions.Single().CreateRuntime();
            }
        }
Exemplo n.º 10
0
 public void Dispose()
 {
     NativeInvoker.coreCvdestroyMat(matObj);
     matObj = IntPtr.Zero;
 }
Exemplo n.º 11
0
 public Mat(int rows, int cols, int type)
 {
     matObj = NativeInvoker.coreCvCreateMat(rows, cols, type);
 }
Exemplo n.º 12
0
 public Mat()
 {
     matObj = NativeInvoker.coreCvCreateEmptyMat();
 }
Exemplo n.º 13
0
 public IntPtr getRow(int row) => IntPtr.Zero != matObj?NativeInvoker.coreCvGetRow(matObj, row) : IntPtr.Zero;
Exemplo n.º 14
0
 public static void resize(Mat src, Mat dst, Size dSize,
                           double fx = 0.0, double fy = 0.0, Interpolation inter = Interpolation.INTER_LINEAR)
 {
     NativeInvoker.coreCvResize(src.MatObj, dst.MatObj, (int)dSize.w, (int)dSize.h, fx, fy, (int)inter);
 }
Exemplo n.º 15
0
 public static void cvtColor(Mat src, Mat dst, CvtColorCode code)
 {
     NativeInvoker.coreCvCvtColor(src.MatObj, dst.MatObj, (int)code);
 }