Exemple #1
0
 /// <summary>
 /// Displays the image in the specified window
 /// </summary>
 /// <param name="winname">Name of the window.</param>
 /// <param name="mat">Image to be shown.</param>
 public static void ImShow(string winname, Mat mat)
 {
     if (string.IsNullOrEmpty(winname))
         throw new ArgumentNullException("winname");
     if (mat == null)
         throw new ArgumentNullException("mat");
     try
     {
         CppInvoke.highgui_imshow(winname, mat.CvPtr);
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
Exemple #2
0
        private static void Main(string[] args)
        {
            var memory = new List<long>(100);
            for (int i = 0; ; i++)
            {
                Mat mat = CvCpp.ImRead(@"img\shapes.png");
                Mat cols = mat.ColRange(10, 100);
                Mat rowsCols = new Mat(mat, new Rect(100,100,200,200));
                cols.GetHashCode();
                rowsCols.GetHashCode();

                memory.Add(MyProcess.WorkingSet64);
                if (memory.Count >= 100)
                {
                    double average = memory.Average();
                    Console.WriteLine("{0:F3}MB", average / 1024.0 / 1024.0);
                    memory.Clear();
                }
            }
            
        }
Exemple #3
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="m"></param>
 /// <param name="rtype"></param>
 /// <param name="alpha"></param>
 /// <param name="beta"></param>
 public void ConvertTo(Mat m, int rtype, double alpha, double beta)
 {
     ThrowIfDisposed();
     if (m == null)
         throw new ArgumentNullException("m");
     try
     {
         CppInvoke.core_Mat_convertTo(ptr, m.CvPtr, rtype, alpha, beta);
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
Exemple #4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="startCol"></param>
 /// <param name="endCol"></param>
 /// <returns></returns>
 public Mat ColRange(int startCol, int endCol)
 {
     ThrowIfDisposed();
     try
     {
         IntPtr retPtr = CppInvoke.core_Mat_colRange(ptr, startCol, endCol);
         Mat retVal = new Mat(retPtr);
         return retVal;
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
Exemple #5
0
 /// <summary>
 /// Saves an image to a specified file.
 /// </summary>
 /// <param name="filename"></param>
 /// <param name="img"></param>
 /// <param name="prms"></param>
 /// <returns></returns>
 public static bool ImWrite(string filename, Mat img, params ImageEncodingParam[] prms)
 {
     if (prms != null)
     {
         List<int> p = new List<int>();
         foreach (ImageEncodingParam item in prms)
         {
             p.Add((int)item.EncodingID);
             p.Add(item.Value);
         }
         return ImWrite(filename, img, p.ToArray());
     }
     else
     {
         return ImWrite(filename, img, (int[])null);
     }
 }
Exemple #6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="m"></param>
 public void PushBack(Mat m)
 {
     throw new NotImplementedException();
     //n_push_back(ptr, m.ptr);
 }
Exemple #7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="m"></param>
 /// <param name="rowRange"></param>
 public Mat(Mat m, Range rowRange)
 {
     ptr = CppInvoke.core_Mat_new(m.ptr, rowRange);
 }
Exemple #8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="m"></param>
 /// <returns></returns>
 public double Dot(Mat m)
 {
     ThrowIfDisposed();
     if (m == null)
         throw new ArgumentNullException("m");
     try
     {
         return CppInvoke.core_Mat_dot(ptr, m.CvPtr);
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
Exemple #9
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="m"></param>
 /// <returns></returns>
 public Mat Cross(Mat m)
 {
     ThrowIfDisposed();
     if(m == null)
         throw new ArgumentNullException("m");
     try
     {
         IntPtr retPtr = CppInvoke.core_Mat_cross(ptr, m.CvPtr);
         Mat retVal = new Mat(retPtr);
         return retVal;
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
Exemple #10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public Mat SetTo(Mat value)
 {
     throw new NotImplementedException();
     //Mat retVal = new Mat(n_setTo(ptr, value.ptr));
     //return retVal;
 }
Exemple #11
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="value"></param>
 /// <param name="mask"></param>
 /// <returns></returns>
 public Mat SetTo(Scalar value, Mat mask)
 {
     throw new NotImplementedException();
     //Mat retVal = new Mat(n_setTo(ptr, value[0], value[1], value[2], value[3], mask.ptr));
     //return retVal;
 }
Exemple #12
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="m"></param>
 /// <param name="roi"></param>
 public Mat(Mat m, Rect roi)
 {
     ptr = CppInvoke.core_Mat_new(m.ptr, roi);
 }
Exemple #13
0
 /// <summary>
 /// Compresses the image and stores it in the memory buffer
 /// </summary>
 /// <param name="ext">The file extension that defines the output format</param>
 /// <param name="img">The image to be written</param>
 /// <param name="buf"></param>
 /// <param name="prms"></param>
 public static void ImEncode(string ext, Mat img, out byte[] buf, params ImageEncodingParam[] prms)
 {
     if (prms != null)
     {
         List<int> p = new List<int>();
         foreach (ImageEncodingParam item in prms)
         {
             p.Add((int)item.EncodingID);
             p.Add(item.Value);
         }
         ImEncode(ext, img, out buf, p.ToArray());
     }
     else
     {
         ImEncode(ext, img, out buf, (int[])null);
     }
 }
Exemple #14
0
 /// <summary>
 /// Compresses the image and stores it in the memory buffer
 /// </summary>
 /// <param name="ext">The file extension that defines the output format</param>
 /// <param name="img">The image to be written</param>
 /// <param name="buf"></param>
 /// <param name="prms"></param>
 public static void ImEncode(string ext, Mat img, out byte[] buf, int[] prms = null)
 {
     if (string.IsNullOrEmpty(ext))
         throw new ArgumentNullException("ext");
     if (img == null)
         throw new ArgumentNullException("img");
     if (prms == null)
         prms = new int[0];
     try
     {
         IntPtr bufMatPtr;
         CppInvoke.highgui_imencode(ext, img.CvPtr, out bufMatPtr, prms, prms.Length);
         {
             CvMat bufMat = new CvMat(bufMatPtr, false);
             buf = new byte[bufMat.Rows * bufMat.Cols];
             Marshal.Copy(bufMat.Data, buf, 0, buf.Length);
         }
         CvInvoke.cvReleaseMat(ref bufMatPtr);
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
Exemple #15
0
 /// <summary>
 /// Reads image from the specified buffer in memory.
 /// </summary>
 /// <param name="buf">The input array of vector of bytes.</param>
 /// <param name="flags">The same flags as in imread</param>
 /// <returns></returns>
 public static Mat ImDecode(Mat buf, LoadMode flags)
 {
     if (buf == null)
         throw new ArgumentNullException("buf");
     try
     {
         IntPtr matPtr = CppInvoke.highgui_imdecode(buf.CvPtr, flags);
         return new Mat(matPtr);
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
Exemple #16
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="m"></param>
 public void CopyTo(Mat m)
 {
     CopyTo(m, null);
 }
Exemple #17
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="m"></param>
 /// <param name="mask"></param>
 public void CopyTo(Mat m, Mat mask)
 {
     ThrowIfDisposed();
     if (m == null)
         throw new ArgumentNullException("m");
     try
     {
         IntPtr maskPtr = GetCvPtr(mask);
         CppInvoke.core_Mat_copyTo(ptr, m.CvPtr, maskPtr);
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
Exemple #18
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="d"></param>
 /// <returns></returns>
 public static Mat Diag(Mat d)
 {
     return d.Diag();
 }
Exemple #19
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="d"></param>
 /// <returns></returns>
 public Mat Diag(MatDiagType d)
 {
     ThrowIfDisposed();
     try
     {
         IntPtr retPtr = CppInvoke.core_Mat_diag(ptr, (int)d);
         Mat retVal = new Mat(retPtr);
         return retVal;
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
Exemple #20
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="dtop"></param>
 /// <param name="dbottom"></param>
 /// <param name="dleft"></param>
 /// <param name="dright"></param>
 /// <returns></returns>
 public Mat AdjustROI(int dtop, int dbottom, int dleft, int dright)
 {
     ThrowIfDisposed();
     try
     {
         IntPtr retPtr = CppInvoke.core_Mat_adjustROI(ptr, dtop, dbottom, dleft, dright);
         Mat retVal = new Mat(retPtr);
         return retVal;
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
Exemple #21
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="method"></param>
 /// <returns></returns>
 public Mat Inv(MatrixDecomposition method)
 {
     ThrowIfDisposed();
     try
     {
         IntPtr retPtr = CppInvoke.core_Mat_inv(ptr, (int)method);
         Mat retVal = new Mat(retPtr);
         return retVal;
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
Exemple #22
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="m"></param>
 /// <param name="type"></param>
 public void AssignTo(Mat m, MatrixType type)
 {
     ThrowIfDisposed();
     if(m == null)
         throw new ArgumentNullException("m");
     try
     {
         CppInvoke.core_Mat_assignTo(ptr, m.CvPtr, (int)type);
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
Exemple #23
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="m"></param>
 /// <param name="scale"></param>
 /// <returns></returns>
 public MatExpr Mul(Mat m, double scale)
 {
     ThrowIfDisposed();
     if (m == null)
         throw new ArgumentNullException();
     try
     {
         IntPtr mPtr = m.CvPtr;
         IntPtr retPtr = CppInvoke.core_Mat_mul(ptr, mPtr, scale);
         MatExpr retVal = new MatExpr(retPtr);
         return retVal;
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
Exemple #24
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="m"></param>
 public void AssignTo(Mat m)
 {
     try
     {
         CppInvoke.core_Mat_assignTo(ptr, m.CvPtr);
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
Exemple #25
0
 /// <summary>
 /// 
 /// </summary>
 /// <returns></returns>
 public Mat Clone()
 {
     ThrowIfDisposed();
     try
     {
         IntPtr retPtr = CppInvoke.core_Mat_clone(ptr);
         Mat retVal = new Mat(retPtr);
         return retVal;
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
Exemple #26
0
 /// <summary>
 /// Saves an image to a specified file.
 /// </summary>
 /// <param name="filename"></param>
 /// <param name="img"></param>
 /// <param name="prms"></param>
 /// <returns></returns>
 public static bool ImWrite(string filename, Mat img, int[] prms = null)
 {
     if (string.IsNullOrEmpty(filename))
         throw new ArgumentNullException("filename");
     if (img == null)
         throw new ArgumentNullException("img");
     if (prms == null)
         prms = new int[0];
     try
     {
         return CppInvoke.highgui_imwrite(filename, img.CvPtr, prms, prms.Length) != 0;
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }