예제 #1
0
 /// <summary>
 ///
 /// </summary>
 public virtual void Clear()
 {
     NativeMethods.HandleException(
         NativeMethods.features2d_BOWTrainer_clear(ptr));
     GC.KeepAlive(this);
 }
예제 #2
0
 protected override void DisposeUnmanaged()
 {
     NativeMethods.HandleException(
         NativeMethods.imgproc_Ptr_CLAHE_delete(ptr));
     base.DisposeUnmanaged();
 }
예제 #3
0
 protected override void DisposeUnmanaged()
 {
     NativeMethods.HandleException(
         NativeMethods.superres_Ptr_FarnebackOpticalFlow_delete(ptr));
     Dispose();
 }
 protected override void DisposeUnmanaged()
 {
     NativeMethods.HandleException(
         NativeMethods.video_Ptr_BackgroundSubtractorMOG2_delete(ptr));
     base.DisposeUnmanaged();
 }
예제 #5
0
 /// <summary>
 /// Default constructor.
 /// You should call FileStorage::open() after initialization.
 /// </summary>
 public FileStorage()
 {
     NativeMethods.HandleException(
         NativeMethods.core_FileStorage_new1(out ptr));
 }
예제 #6
0
 /// <summary>
 /// Creates empty SparseMat
 /// </summary>
 public SparseMat()
 {
     NativeMethods.HandleException(
         NativeMethods.core_SparseMat_new1(out ptr));
 }
예제 #7
0
 protected override void DisposeUnmanaged()
 {
     NativeMethods.HandleException(
         NativeMethods.stitching_Ptr_Stitcher_delete(ptr));
     base.DisposeUnmanaged();
 }
예제 #8
0
 /// <summary>
 /// Releases unmanaged resources
 /// </summary>
 protected override void DisposeUnmanaged()
 {
     NativeMethods.HandleException(
         NativeMethods.objdetect_CascadeClassifier_delete(ptr));
     base.DisposeUnmanaged();
 }
예제 #9
0
 protected override void DisposeUnmanaged()
 {
     NativeMethods.HandleException(
         NativeMethods.photo_Ptr_CalibrateDebevec_delete(ptr));
     base.DisposeUnmanaged();
 }
예제 #10
0
        /// <summary>
        /// Draws the found matches of keypoints from two images.
        /// </summary>
        /// <param name="img1">First source image.</param>
        /// <param name="keypoints1">Keypoints from the first source image.</param>
        /// <param name="img2">Second source image.</param>
        /// <param name="keypoints2">Keypoints from the second source image.</param>
        /// <param name="matches1To2">Matches from the first image to the second one, which means that keypoints1[i]
        /// has a corresponding point in keypoints2[matches[i]] .</param>
        /// <param name="outImg">Output image. Its content depends on the flags value defining what is drawn in the
        /// output image. See possible flags bit values below.</param>
        /// <param name="matchColor">Color of matches (lines and connected keypoints). If matchColor==Scalar::all(-1),
        /// the color is generated randomly.</param>
        /// <param name="singlePointColor">Color of single keypoints (circles), which means that keypoints do not
        /// have the matches. If singlePointColor==Scalar::all(-1) , the color is generated randomly.</param>
        /// <param name="matchesMask">Mask determining which matches are drawn. If the mask is empty, all matches are drawn.</param>
        /// <param name="flags">Flags setting drawing features. Possible flags bit values are defined by DrawMatchesFlags.</param>
        public static void DrawMatchesKnn(
            Mat img1,
            IEnumerable <KeyPoint> keypoints1,
            Mat img2,
            IEnumerable <KeyPoint> keypoints2,
            IEnumerable <IEnumerable <DMatch> > matches1To2,
            Mat outImg,
            Scalar?matchColor       = null,
            Scalar?singlePointColor = null,
            IEnumerable <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();

            var keypoints1Array   = keypoints1 as KeyPoint[] ?? keypoints1.ToArray();
            var keypoints2Array   = keypoints2 as KeyPoint[] ?? keypoints2.ToArray();
            var matches1To2Array  = matches1To2.Select(m => m.ToArray()).ToArray();
            var matches1To2Size1  = matches1To2Array.Length;
            var matches1To2Size2  = matches1To2Array.Select(dm => dm.Length).ToArray();
            var matchColor0       = matchColor.GetValueOrDefault(Scalar.All(-1));
            var singlePointColor0 = singlePointColor.GetValueOrDefault(Scalar.All(-1));

            using var matches1To2Ptr = new ArrayAddress2 <DMatch>(matches1To2Array);
            if (matchesMask == null)
            {
                NativeMethods.HandleException(
                    NativeMethods.features2d_drawMatchesKnn(
                        img1.CvPtr, keypoints1Array, keypoints1Array.Length,
                        img2.CvPtr, keypoints2Array, keypoints2Array.Length,
                        matches1To2Ptr, matches1To2Size1, matches1To2Size2,
                        outImg.CvPtr, matchColor0, singlePointColor0,
                        null, 0, null, (int)flags));
            }
            else
            {
                var matchesMaskArray = matchesMask.Select(m => m.ToArray()).ToArray();
                var matchesMaskSize1 = matches1To2Array.Length;
                var matchesMaskSize2 = matchesMaskArray.Select(dm => dm.Length).ToArray();
                using var matchesMaskPtr = new ArrayAddress2 <byte>(matchesMaskArray);
                NativeMethods.HandleException(
                    NativeMethods.features2d_drawMatchesKnn(
                        img1.CvPtr, keypoints1Array, keypoints1Array.Length,
                        img2.CvPtr, keypoints2Array, keypoints2Array.Length,
                        matches1To2Ptr.Pointer, matches1To2Size1, matches1To2Size2,
                        outImg.CvPtr, matchColor0, singlePointColor0,
                        matchesMaskPtr, matchesMaskSize1, matchesMaskSize2, (int)flags));
            }
            GC.KeepAlive(img1);
            GC.KeepAlive(img2);
            GC.KeepAlive(outImg);
        }
예제 #11
0
 /// <summary>
 /// Default constructor
 /// </summary>
 public CascadeClassifier()
 {
     NativeMethods.HandleException(
         NativeMethods.objdetect_CascadeClassifier_new(out ptr));
 }
예제 #12
0
        // MP! Added: To correctly support imShow under WinRT.

        /// <summary>
        /// Initialize XAML container panel for use by ImShow
        /// </summary>
        /// <param name="panel">Panel container.</param>
        public static void InitContainer(object panel)
        {
            NativeMethods.HandleException(
                NativeMethods.highgui_initContainer(panel));
        }
예제 #13
0
 /// <summary>
 /// Destroys all of the HighGUI windows.
 /// </summary>
 public static void DestroyAllWindows()
 {
     NativeMethods.HandleException(
         NativeMethods.highgui_destroyAllWindows());
 }
예제 #14
0
 protected override void DisposeUnmanaged()
 {
     NativeMethods.HandleException(
         NativeMethods.superres_Ptr_SuperResolution_delete(ptr));
     base.DisposeUnmanaged();
 }
예제 #15
0
 /// <summary>
 /// The default constructor
 /// </summary>
 public FileNodeIterator()
 {
     NativeMethods.HandleException(
         NativeMethods.core_FileNodeIterator_new1(out ptr));
 }
 protected override void DisposeUnmanaged()
 {
     NativeMethods.HandleException(
         NativeMethods.features2d_Ptr_AgastFeatureDetector_delete(ptr));
     base.DisposeUnmanaged();
 }
예제 #17
0
 /// <summary>
 /// Releases unmanaged resources
 /// </summary>
 protected override void DisposeUnmanaged()
 {
     NativeMethods.HandleException(
         NativeMethods.features2d_BOWImgDescriptorExtractor_delete(ptr));
     base.DisposeUnmanaged();
 }
예제 #18
0
        /// <summary>
        /// 初期化
        /// </summary>
        /// <param name="name">トラックバーの名前</param>
        /// <param name="window">トラックバーの親ウィンドウ名</param>
        /// <param name="value">スライダの初期位置</param>
        /// <param name="max">スライダの最大値.最小値は常に 0.</param>
        /// <param name="callback">スライダの位置が変更されるたびに呼び出されるデリゲート</param>
        /// <param name="userdata"></param>
#else
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="name">Trackbar name</param>
        /// <param name="window">Window name</param>
        /// <param name="value">Initial slider position</param>
        /// <param name="max">The upper limit of the range this trackbar is working with. </param>
        /// <param name="callback">Callback handler</param>
        /// <param name="userdata"></param>
#endif
        public CvTrackbar(string name, string window, int value, int max, CvTrackbarCallback2 callback, object?userdata)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (string.IsNullOrEmpty(window))
            {
                throw new ArgumentNullException(nameof(window));
            }

            this.name     = name;
            this.window   = window;
            this.value    = value;
            this.max      = max;
            this.callback = callback ?? throw new ArgumentNullException(nameof(callback));
            this.userdata = userdata;

            // userdataをIntPtrに変換
            IntPtr userdataPtr;

            if (userdata != null)
            {
                gchUserdata = GCHandle.Alloc(userdata);
                userdataPtr = GCHandle.ToIntPtr(gchUserdata);
            }
            else
            {
                userdataPtr = IntPtr.Zero;
            }

            this.callback = callback;
            // コールバックdelegateを、userdataをobjectとするように変換
            callbackNative = (pos, ud) =>
            {
                if (ud == IntPtr.Zero)
                {
                    callback(pos, null);
                }
                else
                {
                    var gch = GCHandle.FromIntPtr(ud);
                    callback(pos, gch.Target);
                }
            };

            // コールバックdelegateをポインタに変換
            gchCallback       = GCHandle.Alloc(callback);
            gchCallbackNative = GCHandle.Alloc(callbackNative);
            var callbackPtr = Marshal.GetFunctionPointerForDelegate(callbackNative);

            //gchValue = GCHandle.Alloc(value, GCHandleType.Pinned);

            NativeMethods.HandleException(
                NativeMethods.highgui_createTrackbar(name, window, ref this.value, max, callbackPtr, userdataPtr, out result));

            if (result == 0)
            {
                throw new OpenCvSharpException("Failed to create CvTrackbar.");
            }
        }
예제 #19
0
 /// <summary>
 /// Sets the trackbar minimum position.
 /// The function sets the minimum position of the specified trackbar in the specified window.
 /// </summary>
 /// <param name="minVal">New minimum position.</param>
 public void SetMin(int minVal)
 {
     NativeMethods.HandleException(
         NativeMethods.highgui_setTrackbarMin(TrackbarName, WindowName, minVal));
 }
예제 #20
0
 /// <summary>
 /// Sets the trackbar maximum position.
 /// The function sets the maximum position of the specified trackbar in the specified window.
 /// </summary>
 /// <param name="maxVal">New maximum position.</param>
 public void SetMax(int maxVal)
 {
     NativeMethods.HandleException(
         NativeMethods.highgui_setTrackbarMax(name, window, maxVal));
 }
예제 #21
0
 protected override void DisposeUnmanaged()
 {
     NativeMethods.HandleException(
         NativeMethods.calib3d_Ptr_StereoSGBM_delete(ptr));
     base.DisposeUnmanaged();
 }
예제 #22
0
 /// <summary>
 /// Releases unmanaged resources
 /// </summary>
 protected override void DisposeUnmanaged()
 {
     NativeMethods.HandleException(
         NativeMethods.videoio_VideoWriter_delete(ptr));
     base.DisposeUnmanaged();
 }
예제 #23
0
 protected override void DisposeUnmanaged()
 {
     NativeMethods.HandleException(
         NativeMethods.wechat_qrcode_Ptr_delete(ptr));
     base.DisposeUnmanaged();
 }
예제 #24
0
 /// <summary>
 /// default constructor.
 ///
 /// The default constructor initializes an empty PCA structure.
 /// The other constructors initialize the structure and call PCA::operator()().
 /// </summary>
 public PCA()
 {
     NativeMethods.HandleException(
         NativeMethods.core_PCA_new1(out ptr));
 }
예제 #25
0
 /// <summary>
 /// Releases unmanaged resources
 /// </summary>
 protected override void DisposeUnmanaged()
 {
     NativeMethods.HandleException(
         NativeMethods.core_FileStorage_delete(ptr));
     base.DisposeUnmanaged();
 }
예제 #26
0
 /// <summary>
 /// Releases unmanaged resources
 /// </summary>
 protected override void DisposeUnmanaged()
 {
     NativeMethods.HandleException(
         NativeMethods.core_OutputArray_delete(ptr));
     base.DisposeUnmanaged();
 }
예제 #27
0
 protected override void DisposeUnmanaged()
 {
     NativeMethods.HandleException(
         NativeMethods.photo_Ptr_TonemapDrago_delete(ptr));
     base.DisposeUnmanaged();
 }
예제 #28
0
 /// <summary>
 /// Clear all inner buffers.
 /// </summary>
 public virtual void CollectGarbage()
 {
     NativeMethods.HandleException(
         NativeMethods.superres_DenseOpticalFlowExt_collectGarbage(ptr));
     GC.KeepAlive(this);
 }
예제 #29
0
 protected override void DisposeUnmanaged()
 {
     NativeMethods.HandleException(
         NativeMethods.features2d_Ptr_FlannBasedMatcher_delete(ptr));
     base.DisposeUnmanaged();
 }
예제 #30
0
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="numComponents"></param>
 public LDA(int numComponents = 0)
 {
     NativeMethods.HandleException(
         NativeMethods.core_LDA_new1(numComponents, out ptr));
 }