當前位置: 首頁>>代碼示例>>C#>>正文


C# Mat.ThrowIfDisposed方法代碼示例

本文整理匯總了C#中OpenCvSharp.Mat.ThrowIfDisposed方法的典型用法代碼示例。如果您正苦於以下問題:C# Mat.ThrowIfDisposed方法的具體用法?C# Mat.ThrowIfDisposed怎麽用?C# Mat.ThrowIfDisposed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在OpenCvSharp.Mat的用法示例。


在下文中一共展示了Mat.ThrowIfDisposed方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: RunByPixelsMask

        /// <summary>
        /// Remove keypoints from some image by mask for pixels of this image.
        /// </summary>
        /// <param name="keypoints"></param>
        /// <param name="mask"></param>
        /// <returns></returns>
        public static KeyPoint[] RunByPixelsMask(IEnumerable<KeyPoint> keypoints, Mat mask)
        {
            if (keypoints == null)
                throw new ArgumentNullException("keypoints");
            if (mask == null) 
                throw new ArgumentNullException("mask");
            mask.ThrowIfDisposed();

            using (var keypointsVec = new VectorOfKeyPoint(keypoints))
            {
                NativeMethods.features2d_KeyPointsFilter_runByPixelsMask(
                    keypointsVec.CvPtr, mask.CvPtr);
                GC.KeepAlive(mask);
                return keypointsVec.ToArray();
            }
        }
開發者ID:JiphuTzu,項目名稱:opencvsharp,代碼行數:22,代碼來源:KeyPointsFilter.cs

示例2: ConvertImage

        /// <summary>
        /// utility function: convert one image to another with optional vertical flip
        /// </summary>
        /// <param name="src"></param>
        /// <param name="dst"></param>
        /// <param name="flags"></param>
        public static void ConvertImage(Mat src, Mat dst, ConvertImageModes flags = ConvertImageModes.None)
        {
            if (src == null)
                throw new ArgumentNullException("src");
            if (dst == null) 
                throw new ArgumentNullException("dst");
            src.ThrowIfDisposed();
            dst.ThrowIfDisposed();
            
            dst.Create(src.Size(), MatType.CV_8UC3);
            NativeMethods.imgcodecs_cvConvertImage_Mat(src.CvPtr, dst.CvPtr, (int)flags);

            GC.KeepAlive(src);
            GC.KeepAlive(dst);
        }
開發者ID:CodeSang,項目名稱:opencvsharp,代碼行數:21,代碼來源:Cv2_imgcodecs.cs

示例3: Merge

        /// <summary>
        /// makes multi-channel array out of several single-channel arrays
        /// </summary>
        /// <param name="mv"></param>
        /// <param name="dst"></param>
        public static void Merge(Mat[] mv, Mat dst)
        {
            if (mv == null)
                throw new ArgumentNullException("mv");
            if (mv.Length == 0)
                throw new ArgumentException("mv.Length == 0");
            if (dst == null)
                throw new ArgumentNullException("dst");
            foreach (Mat m in mv)
            {
                if(m == null)
                    throw new ArgumentException("mv contains null element");
                m.ThrowIfDisposed();
            }
            dst.ThrowIfDisposed();

            var mvPtr = new IntPtr[mv.Length];
            for (int i = 0; i < mv.Length; i++)
            {
                mvPtr[i] = mv[i].CvPtr;
            }
            NativeMethods.core_merge(mvPtr, (uint)mvPtr.Length, dst.CvPtr);
            GC.KeepAlive(mv);
            GC.KeepAlive(dst);
        }
開發者ID:fdncred,項目名稱:opencvsharp,代碼行數:30,代碼來源:Cv2_core.cs

示例4: Abs

 /// <summary>
 /// Computes absolute value of each matrix element
 /// </summary>
 /// <param name="src">matrix</param>
 /// <returns></returns>
 public static MatExpr Abs(Mat src)
 {
     if (src == null)
         throw new ArgumentNullException("src");
     src.ThrowIfDisposed();
     IntPtr retPtr = NativeMethods.core_abs_Mat(src.CvPtr);
     GC.KeepAlive(src);
     return new MatExpr(retPtr);
 }
開發者ID:fdncred,項目名稱:opencvsharp,代碼行數:14,代碼來源:Cv2_core.cs

示例5: Min

 /// <summary>
 /// computes per-element minimum of two arrays (dst = min(src1, src2))
 /// </summary>
 /// <param name="src1"></param>
 /// <param name="src2"></param>
 /// <param name="dst"></param>
 public static void Min(Mat src1, Mat src2, Mat dst)
 {
     if (src1 == null)
         throw new ArgumentNullException("src1");
     if (src2 == null)
         throw new ArgumentNullException("src2");
     if (dst == null)
         throw new ArgumentNullException("dst");
     src1.ThrowIfDisposed();
     src2.ThrowIfDisposed();
     dst.ThrowIfDisposed();
     NativeMethods.core_min_MatMat(src1.CvPtr, src2.CvPtr, dst.CvPtr);
     GC.KeepAlive(src1);
     GC.KeepAlive(src2);
     GC.KeepAlive(dst);
 }
開發者ID:fdncred,項目名稱:opencvsharp,代碼行數:22,代碼來源:Cv2_core.cs

示例6: Read

        /// <summary>
        /// カメラやビデオファイルから一つのフレームを取り出し,それを展開して返す.
        /// この関數は,単純にcvGrabFrame とcvRetrieveFrame をまとめて呼び出しているだけである.
        /// 返された畫像は,ユーザが解放したり,変更したりするべきではない.
        /// </summary>
        /// <returns>1フレームの畫像 (GC禁止フラグが立っている). キャプチャできなかった場合はnull.</returns>
#else
        /// <summary>
        /// Grabs a frame from camera or video file, decompresses and returns it. 
        /// This function is just a combination of cvGrabFrame and cvRetrieveFrame in one call. 
        /// The returned image should not be released or modified by user. 
        /// </summary>
        /// <returns></returns>
#endif
        public bool Read(Mat image)
        {
            ThrowIfDisposed();
            if(image == null)
                throw new ArgumentNullException("image");
            image.ThrowIfDisposed();
            
            //NativeMethods.videoio_VideoCapture_read(ptr, image.CvPtr);
            /*
            bool grabbed = NativeMethods.videoio_VideoCapture_grab(ptr) != 0;
            if (!grabbed)
                return false;
            */
            NativeMethods.videoio_VideoCapture_operatorRightShift_Mat(ptr, image.CvPtr);
            GC.KeepAlive(image);
            return true;
        }
開發者ID:Bobanaut,項目名稱:opencvsharp,代碼行數:31,代碼來源:VideoCapture.cs

示例7: Retrieve

        /// <summary>
        /// GrabFrame 関數によって取り出された畫像への參照を返す.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="channel">non-zero streamIdx is only valid for multi-head camera live streams</param>
        /// <returns>1フレームの畫像 (GC禁止フラグが立っている). キャプチャできなかった場合はnull.</returns>
#else
        /// <summary>
        /// Decodes and returns the grabbed video frame.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="channel">non-zero streamIdx is only valid for multi-head camera live streams</param>
        /// <returns></returns>
#endif
        public bool Retrieve(Mat image, int channel = 0)
        {
            ThrowIfDisposed();
            if (image == null)
                throw new ArgumentNullException("image");
            image.ThrowIfDisposed();
            return NativeMethods.videoio_VideoCapture_retrieve(ptr, image.CvPtr, channel) != 0;
        }
開發者ID:Bobanaut,項目名稱:opencvsharp,代碼行數:22,代碼來源:VideoCapture.cs

示例8: DrawKeypoints

        /// <summary>
        /// Draw keypoints.
        /// </summary>
        /// <param name="image"></param>
        /// <param name="keypoints"></param>
        /// <param name="outImage"></param>
        /// <param name="color"></param>
        /// <param name="flags"></param>
        public static void DrawKeypoints(Mat image, IEnumerable<KeyPoint> keypoints, Mat outImage,
            Scalar? color = null, DrawMatchesFlags flags = DrawMatchesFlags.Default)
        {
            if (image == null)
                throw new ArgumentNullException(nameof(image));
            if (outImage == null)
                throw new ArgumentNullException(nameof(outImage));
            if (keypoints == null)
                throw new ArgumentNullException(nameof(keypoints));
            image.ThrowIfDisposed();
            outImage.ThrowIfDisposed();

            KeyPoint[] keypointsArray = EnumerableEx.ToArray(keypoints);
            Scalar color0 = color.GetValueOrDefault(Scalar.All(-1));
            NativeMethods.features2d_drawKeypoints(image.CvPtr, keypointsArray, keypointsArray.Length,
                outImage.CvPtr, color0, (int)flags);
        }
開發者ID:shimat,項目名稱:opencvsharp,代碼行數:25,代碼來源:Cv2_features2d.cs

示例9: Detect

        /// <summary>
        /// Performs object detection without a multi-scale window.
        /// </summary>
        /// <param name="img">Source image. CV_8UC1 and CV_8UC4 types are supported for now.</param>
        /// <param name="weights"></param>
        /// <param name="hitThreshold">Threshold for the distance between features and SVM classifying plane. 
        /// Usually it is 0 and should be specfied in the detector coefficients (as the last free coefficient). 
        /// But if the free coefficient is omitted (which is allowed), you can specify it manually here.</param>
        /// <param name="winStride">Window stride. It must be a multiple of block stride.</param>
        /// <param name="padding">Mock parameter to keep the CPU interface compatibility. It must be (0,0).</param>
        /// <param name="searchLocations"></param>
        /// <returns>Left-top corner points of detected objects boundaries.</returns>
        public virtual Point[] Detect(Mat img, out double[] weights, 
            double hitThreshold = 0, Size? winStride = null, Size? padding = null, Point[] searchLocations = null)
        {
            if (disposed)
                throw new ObjectDisposedException("HOGDescriptor");
            if (img == null)
                throw new ArgumentNullException(nameof(img));
            img.ThrowIfDisposed();

            Size winStride0 = winStride.GetValueOrDefault(new Size());
            Size padding0 = padding.GetValueOrDefault(new Size());
            using (var flVec = new VectorOfPoint())
            using (var weightsVec = new VectorOfDouble())
            {
                int slLength = (searchLocations != null) ? searchLocations.Length : 0;
                NativeMethods.objdetect_HOGDescriptor_detect(ptr, img.CvPtr, flVec.CvPtr, weightsVec.CvPtr,
                    hitThreshold, winStride0, padding0, searchLocations, slLength);
                weights = weightsVec.ToArray();
                return flVec.ToArray();
            }
        }
開發者ID:shimat,項目名稱:opencvsharp,代碼行數:33,代碼來源:HOGDescriptor.cs

示例10: Mul

 /// <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);
         MatExpr retVal = new MatExpr(retPtr);
         return retVal;
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
開發者ID:CodeSang,項目名稱:opencvsharp,代碼行數:21,代碼來源:MatExpr.cs

示例11: Dot

 /// <summary>
 /// 
 /// </summary>
 /// <param name="m"></param>
 /// <returns></returns>
 public double Dot(Mat m)
 {
     ThrowIfDisposed();
     m.ThrowIfDisposed();
     try
     {
         return NativeMethods.core_MatExpr_dot(ptr, m.CvPtr);
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
開發者ID:CodeSang,項目名稱:opencvsharp,代碼行數:18,代碼來源:MatExpr.cs

示例12: Cross

 /// <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);
         Mat retVal = new Mat(retPtr);
         return retVal;
     }
     catch (BadImageFormatException ex)
     {
         throw PInvokeHelper.CreateException(ex);
     }
 }
開發者ID:CodeSang,項目名稱:opencvsharp,代碼行數:20,代碼來源:MatExpr.cs

示例13: Correct

        /// <summary>
        /// updates the predicted state from the measurement
        /// </summary>
        /// <param name="measurement"></param>
        /// <returns></returns>
        public Mat Correct(Mat measurement)
        {
            if (disposed)
                throw new ObjectDisposedException("KalmanFilter");
            if (measurement == null)
                throw new ArgumentNullException("measurement");
            measurement.ThrowIfDisposed();

            IntPtr ret = NativeMethods.video_KalmanFilter_correct(ptr, measurement.CvPtr);
            return new Mat(ret);
        }
開發者ID:JiphuTzu,項目名稱:opencvsharp,代碼行數:16,代碼來源:KalmanFilter.cs

示例14: ImDecode

 /// <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, ImreadModes flags)
 {
     if (buf == null)
         throw new ArgumentNullException("buf");
     buf.ThrowIfDisposed();
     IntPtr matPtr = NativeMethods.imgcodecs_imdecode_Mat(buf.CvPtr, (int) flags);
     GC.KeepAlive(buf);
     return new Mat(matPtr);
 }
開發者ID:CodeSang,項目名稱:opencvsharp,代碼行數:15,代碼來源:Cv2_imgcodecs.cs

示例15: DrawMatches

        /// <summary>
        /// Draws matches of keypints from two images on output image.
        /// </summary>
        /// <param name="img1"></param>
        /// <param name="keypoints1"></param>
        /// <param name="img2"></param>
        /// <param name="keypoints2"></param>
        /// <param name="matches1To2"></param>
        /// <param name="outImg"></param>
        /// <param name="matchColor"></param>
        /// <param name="singlePointColor"></param>
        /// <param name="matchesMask"></param>
        /// <param name="flags"></param>
        public static void DrawMatches(Mat img1, IEnumerable<KeyPoint> keypoints1,
            Mat img2, IEnumerable<KeyPoint> keypoints2,
            IEnumerable<DMatch> matches1To2, Mat outImg,
            Scalar? matchColor = null, Scalar? singlePointColor = null,
            IEnumerable<byte> matchesMask = null, DrawMatchesFlags flags = DrawMatchesFlags.Default)
        {
            if (img1 == null)
                throw new ArgumentNullException(nameof(img1));
            if (img2 == null)
                throw new ArgumentNullException(nameof(img2));
            if (outImg == null)
                throw new ArgumentNullException(nameof(outImg));
            if (keypoints1 == null)
                throw new ArgumentNullException(nameof(keypoints1));
            if (keypoints2 == null)
                throw new ArgumentNullException(nameof(keypoints2));
            if (matches1To2 == null)
                throw new ArgumentNullException(nameof(matches1To2));
            img1.ThrowIfDisposed();
            img2.ThrowIfDisposed();
            outImg.ThrowIfDisposed();

            KeyPoint[] keypoints1Array = EnumerableEx.ToArray(keypoints1);
            KeyPoint[] keypoints2Array = EnumerableEx.ToArray(keypoints2);
            DMatch[] matches1To2Array = EnumerableEx.ToArray(matches1To2);
            Scalar matchColor0 = matchColor.GetValueOrDefault(Scalar.All(-1));
            Scalar singlePointColor0 = singlePointColor.GetValueOrDefault(Scalar.All(-1));

            byte[] matchesMaskArray = null;
            int matchesMaskLength = 0;
            if (matchesMask != null)
            {
                matchesMaskArray = EnumerableEx.ToArray(matchesMask);
                matchesMaskLength = matchesMaskArray.Length;
            }

            NativeMethods.features2d_drawMatches1(img1.CvPtr, keypoints1Array, keypoints1Array.Length,
                img2.CvPtr, keypoints2Array, keypoints2Array.Length,
                matches1To2Array, matches1To2Array.Length, outImg.CvPtr,
                matchColor0, singlePointColor0, matchesMaskArray, matchesMaskLength, (int)flags);
        }
開發者ID:shimat,項目名稱:opencvsharp,代碼行數:54,代碼來源:Cv2_features2d.cs


注:本文中的OpenCvSharp.Mat.ThrowIfDisposed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。