コード例 #1
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 NativeMethods.highgui_imwrite(fileName, img.CvPtr, prms, prms.Length) != 0;
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
コード例 #2
0
ファイル: MatExpr.cs プロジェクト: yushuiqiang/opencvsharp
 /// <summary>
 ///
 /// </summary>
 /// <param name="m"></param>
 /// <returns></returns>
 public Mat Cross(Mat m)
 {
     ThrowIfDisposed();
     m.ThrowIfDisposed();
     try
     {
         IntPtr retPtr = NativeMethods.core_MatExpr_cross(ptr, m.CvPtr);
         GC.KeepAlive(this);
         GC.KeepAlive(m);
         Mat retVal = new Mat(retPtr);
         return(retVal);
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
コード例 #3
0
        /// <summary>
        /// Checks whether PInvoke functions can be called
        /// </summary>
        public static void TryPInvoke()
        {
            if (tried)
            {
                return;
            }
            tried = true;

            try
            {
                core_Mat_sizeof();
            }
            catch (DllNotFoundException e)
            {
                var exception = PInvokeHelper.CreateException(e);
#if !uwp && !uap10
                try{ Console.WriteLine(exception.Message); }
                catch {}
#endif
                try{ Debug.WriteLine(exception.Message); }
                catch {}
                throw exception;
            }
            catch (BadImageFormatException e)
            {
                var exception = PInvokeHelper.CreateException(e);
#if !uwp && !uap10
                try { Console.WriteLine(exception.Message); }
                catch { }
#endif
                try { Debug.WriteLine(exception.Message); }
                catch { }
                throw exception;
            }
            catch (Exception e)
            {
                Exception ex = e.InnerException ?? e;
#if !uwp && !uap10
                try{ Console.WriteLine(ex.Message); }
                catch {}
#endif
                try { Debug.WriteLine(ex.Message); }
                catch {}
                throw;
            }
        }
コード例 #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="e"></param>
 /// <param name="s"></param>
 /// <returns></returns>
 public static MatExpr operator *(MatExpr e, double s)
 {
     if (e == null)
     {
         throw new ArgumentNullException("nameof(e)");
     }
     e.ThrowIfDisposed();
     try
     {
         IntPtr retPtr = NativeMethods.core_operatorMultiply_MatExprDouble(e.CvPtr, s);
         return(new MatExpr(retPtr));
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
コード例 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="e"></param>
 /// <param name="s"></param>
 /// <returns></returns>
 public static MatExpr operator +(MatExpr e, Scalar s)
 {
     if (e == null)
     {
         throw new ArgumentNullException(nameof(e));
     }
     e.ThrowIfDisposed();
     try
     {
         IntPtr retPtr = NativeMethods.core_operatorAdd_MatExprScalar(e.CvPtr, s);
         return(new MatExpr(retPtr));
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
コード例 #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="s"></param>
 /// <param name="e"></param>
 /// <returns></returns>
 public static MatExpr operator -(Scalar s, MatExpr e)
 {
     if (e == null)
     {
         throw new ArgumentNullException(nameof(e));
     }
     e.ThrowIfDisposed();
     try
     {
         IntPtr retPtr = NativeMethods.core_operatorSubtract_ScalarMatExpr(s, e.CvPtr);
         return(new MatExpr(retPtr));
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
コード例 #7
0
        /// <summary>
        /// Checks whether PInvoke functions can be called
        /// </summary>
        public static void TryPInvoke()
        {
            if (tried)
            {
                return;
            }
            tried = true;

            try
            {
                core_Mat_sizeof();
            }
            catch (DllNotFoundException e)
            {
                var exception = PInvokeHelper.CreateException(e);
                try{ Console.WriteLine(exception.Message); }
                // ReSharper disable once EmptyGeneralCatchClause
                catch { }
                try{ Debug.WriteLine(exception.Message); }
                // ReSharper disable once EmptyGeneralCatchClause
                catch { }
                throw exception;
            }
            catch (BadImageFormatException e)
            {
                var exception = PInvokeHelper.CreateException(e);
                try { Console.WriteLine(exception.Message); }
                // ReSharper disable once EmptyGeneralCatchClause
                catch { }
                try { Debug.WriteLine(exception.Message); }
                // ReSharper disable once EmptyGeneralCatchClause
                catch { }
                throw exception;
            }
            catch (Exception e)
            {
                var ex = e.InnerException ?? e;
                try{ Console.WriteLine(ex.Message); }
                // ReSharper disable once EmptyGeneralCatchClause
                catch { }
                try { Debug.WriteLine(ex.Message); }
                // ReSharper disable once EmptyGeneralCatchClause
                catch { }
                throw;
            }
        }
コード例 #8
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="e"></param>
 /// <returns></returns>
 public static MatExpr operator ~(MatExpr e)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     e.ThrowIfDisposed();
     try
     {
         IntPtr retPtr = NativeMethods.core_operatorUnaryNot_MatExpr(e.CvPtr);
         return(new MatExpr(retPtr));
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
コード例 #9
0
ファイル: MatExpr.cs プロジェクト: yushuiqiang/opencvsharp
 /// <summary>
 ///
 /// </summary>
 /// <param name="m"></param>
 /// <param name="scale"></param>
 /// <returns></returns>
 public MatExpr Mul(Mat m, double scale = 1.0)
 {
     ThrowIfDisposed();
     m.ThrowIfDisposed();
     try
     {
         IntPtr retPtr = NativeMethods.core_MatExpr_mul_toMat(ptr, m.CvPtr, scale);
         GC.KeepAlive(this);
         GC.KeepAlive(m);
         MatExpr retVal = new MatExpr(retPtr);
         return(retVal);
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
コード例 #10
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="s"></param>
 /// <param name="e"></param>
 /// <returns></returns>
 public static MatExpr operator /(double s, MatExpr e)
 {
     if (e == null)
     {
         throw new ArgumentNullException("nameof(e)");
     }
     e.ThrowIfDisposed();
     try
     {
         IntPtr retPtr = NativeMethods.core_operatorDivide_DoubleMatExpr(s, e.CvPtr);
         return(new MatExpr(retPtr));
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
コード例 #11
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="e"></param>
 /// <param name="s"></param>
 /// <returns></returns>
 public static MatExpr operator /(MatExpr e, double s)
 {
     if (e == null)
     {
         throw new ArgumentNullException(nameof(e));
     }
     e.ThrowIfDisposed();
     try
     {
         var retPtr = NativeMethods.core_operatorDivide_MatExprDouble(e.CvPtr, s);
         GC.KeepAlive(e);
         return(new MatExpr(retPtr));
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
コード例 #12
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("nameof(winname)");
     }
     if (mat == null)
     {
         throw new ArgumentNullException("nameof(mat)");
     }
     try
     {
         NativeMethods.highgui_imshow(winname, mat.CvPtr);
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
コード例 #13
0
        /// <summary>
        /// PInvokeが正常に行えるかチェックする
        /// </summary>
#else
        /// <summary>
        /// Checks whether PInvoke functions can be called
        /// </summary>
#endif
        private static void TryPInvoke()
        {
            if (tried)
            {
                return;
            }
            tried = true;

            try
            {
                core_Mat_sizeof();
            }
            catch (DllNotFoundException e)
            {
                var exception = PInvokeHelper.CreateException(e);
                try
                {
                    Console.WriteLine(exception.Message);
                }
                catch { }
                try
                {
                    Debug.WriteLine(exception.Message);
                }
                catch { }
                throw exception;
            }
            catch (BadImageFormatException e)
            {
                var exception = PInvokeHelper.CreateException(e);
                try
                {
                    Console.WriteLine(exception.Message);
                }
                catch { }
                try
                {
                    Debug.WriteLine(exception.Message);
                }
                catch { }
                throw exception;
            }
        }
コード例 #14
0
ファイル: MatExpr.cs プロジェクト: inohiroki/opencvsharp
 /// <summary>
 ///
 /// </summary>
 /// <param name="e1"></param>
 /// <param name="e2"></param>
 /// <returns></returns>
 public static MatExpr operator /(MatExpr e1, MatExpr e2)
 {
     if (e1 == null)
     {
         throw new ArgumentNullException("e1");
     }
     if (e2 == null)
     {
         throw new ArgumentNullException("e2");
     }
     e1.ThrowIfDisposed();
     e2.ThrowIfDisposed();
     try
     {
         IntPtr retPtr = NativeMethods.core_operatorDivide_MatExprMatExpr(e1.CvPtr, e2.CvPtr);
         return(new MatExpr(retPtr));
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
コード例 #15
0
ファイル: MatExpr.cs プロジェクト: inohiroki/opencvsharp
 /// <summary>
 ///
 /// </summary>
 /// <param name="m"></param>
 /// <param name="e"></param>
 /// <returns></returns>
 public static MatExpr operator /(Mat m, MatExpr e)
 {
     if (m == null)
     {
         throw new ArgumentNullException("m");
     }
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     m.ThrowIfDisposed();
     e.ThrowIfDisposed();
     try
     {
         IntPtr retPtr = NativeMethods.core_operatorDivide_MatMatExpr(m.CvPtr, e.CvPtr);
         return(new MatExpr(retPtr));
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
コード例 #16
0
ファイル: MatExpr.cs プロジェクト: inohiroki/opencvsharp
 /// <summary>
 ///
 /// </summary>
 /// <param name="e"></param>
 /// <param name="m"></param>
 /// <returns></returns>
 public static MatExpr operator *(MatExpr e, Mat m)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     if (m == null)
     {
         throw new ArgumentNullException("m");
     }
     e.ThrowIfDisposed();
     m.ThrowIfDisposed();
     try
     {
         IntPtr retPtr = NativeMethods.core_operatorMultiply_MatExprMat(e.CvPtr, m.CvPtr);
         return(new MatExpr(retPtr));
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
コード例 #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="e"></param>
 /// <param name="m"></param>
 /// <returns></returns>
 public static MatExpr operator -(MatExpr e, Mat m)
 {
     if (e == null)
     {
         throw new ArgumentNullException(nameof(e));
     }
     if (m == null)
     {
         throw new ArgumentNullException(nameof(m));
     }
     e.ThrowIfDisposed();
     m.ThrowIfDisposed();
     try
     {
         var retPtr = NativeMethods.core_operatorSubtract_MatExprMat(e.CvPtr, m.CvPtr);
         GC.KeepAlive(e);
         GC.KeepAlive(m);
         return(new MatExpr(retPtr));
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
コード例 #18
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="e1"></param>
 /// <param name="e2"></param>
 /// <returns></returns>
 public static MatExpr operator *(MatExpr e1, MatExpr e2)
 {
     if (e1 == null)
     {
         throw new ArgumentNullException(nameof(e1));
     }
     if (e2 == null)
     {
         throw new ArgumentNullException(nameof(e2));
     }
     e1.ThrowIfDisposed();
     e2.ThrowIfDisposed();
     try
     {
         IntPtr retPtr = NativeMethods.core_operatorMultiply_MatExprMatExpr(e1.CvPtr, e2.CvPtr);
         GC.KeepAlive(e1);
         GC.KeepAlive(e2);
         return(new MatExpr(retPtr));
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
コード例 #19
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="m"></param>
 /// <param name="e"></param>
 /// <returns></returns>
 public static MatExpr operator *(Mat m, MatExpr e)
 {
     if (m == null)
     {
         throw new ArgumentNullException(nameof(m));
     }
     if (e == null)
     {
         throw new ArgumentNullException(nameof(e));
     }
     m.ThrowIfDisposed();
     e.ThrowIfDisposed();
     try
     {
         IntPtr retPtr = NativeMethods.core_operatorMultiply_MatMatExpr(m.CvPtr, e.CvPtr);
         GC.KeepAlive(m);
         GC.KeepAlive(e);
         return(new MatExpr(retPtr));
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }