Example #1
0
 /// <summary>
 /// Writes data to a file storage.
 /// </summary>
 /// <param name="val"></param>
 public FileStorage Add(IEnumerable <KeyPoint> val)
 {
     if (val == null)
     {
         throw new ArgumentNullException(nameof(val));
     }
     ThrowIfDisposed();
     using (var valVec = new VectorOfKeyPoint(val))
     {
         NativeMethods.HandleException(
             NativeMethods.core_FileStorage_shift_vectorOfKeyPoint(ptr, valVec.CvPtr));
     }
     GC.KeepAlive(this);
     return(this);
 }
Example #2
0
        /// <summary>
        /// Detects corners using the FAST algorithm
        /// </summary>
        /// <param name="image">grayscale image where keypoints (corners) are detected.</param>
        /// <param name="threshold">threshold on difference between intensity of the central pixel
        /// and pixels of a circle around this pixel.</param>
        /// <param name="nonmaxSupression">if true, non-maximum suppression is applied to
        /// detected corners (keypoints).</param>
        /// <param name="type">one of the three neighborhoods as defined in the paper</param>
        /// <returns>keypoints detected on the image.</returns>
        public static KeyPoint[] FAST(InputArray image, int threshold, bool nonmaxSupression, FASTType type)
        {
            if (image == null)
            {
                throw new ArgumentNullException("nameof(image)");
            }
            image.ThrowIfDisposed();

            using (var kp = new VectorOfKeyPoint())
            {
                NativeMethods.features2d_FAST2(image.CvPtr, kp.CvPtr, threshold, nonmaxSupression ? 1 : 0, (int)type);
                GC.KeepAlive(image);
                return(kp.ToArray());
            }
        }
Example #3
0
        /// <summary>
        /// Remove keypoints of sizes out of range.
        /// </summary>
        /// <param name="keypoints"></param>
        /// <param name="minSize"></param>
        /// <param name="maxSize"></param>
        /// <returns></returns>
        public static KeyPoint[] RunByKeypointSize(IEnumerable <KeyPoint> keypoints, float minSize,
                                                   float maxSize = Single.MaxValue)
        {
            if (keypoints == null)
            {
                throw new ArgumentNullException("nameof(keypoints)");
            }

            using (var keypointsVec = new VectorOfKeyPoint(keypoints))
            {
                NativeMethods.features2d_KeyPointsFilter_runByKeypointSize(
                    keypointsVec.CvPtr, minSize, maxSize);
                return(keypointsVec.ToArray());
            }
        }
Example #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="name"></param>
 /// <param name="value"></param>
 public void Write(string name, IEnumerable <KeyPoint> value)
 {
     if (name == null)
     {
         throw new ArgumentNullException(nameof(name));
     }
     if (value == null)
     {
         throw new ArgumentNullException(nameof(value));
     }
     using (var valueVector = new VectorOfKeyPoint(value))
     {
         NativeMethods.core_FileStorage_write_vectorOfKeyPoint(ptr, name, valueVector.CvPtr);
     }
 }
        /// <summary>
        /// Detects corners using the AGAST algorithm
        /// </summary>
        /// <param name="image">grayscale image where keypoints (corners) are detected.</param>
        /// <param name="threshold">threshold on difference between intensity of the central pixel
        /// and pixels of a circle around this pixel.</param>
        /// <param name="nonmaxSuppression">if true, non-maximum suppression is applied to
        /// detected corners (keypoints).</param>
        /// <param name="type">one of the four neighborhoods as defined in the paper</param>
        /// <returns>keypoints detected on the image.</returns>
        public static KeyPoint[] AGAST(InputArray image, int threshold, bool nonmaxSuppression, AgastFeatureDetector.DetectorType type)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            image.ThrowIfDisposed();

            using (var vector = new VectorOfKeyPoint())
            {
                NativeMethods.features2d_AGAST(image.CvPtr, vector.CvPtr, threshold, nonmaxSuppression ? 1 : 0,
                                               (int)type);
                GC.KeepAlive(image);
                return(vector.ToArray());
            }
        }
Example #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="name"></param>
        /// <param name="value"></param>
        public void Write(string name, IEnumerable <KeyPoint> value)
        {
            ThrowIfDisposed();
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }
            if (value == null)
            {
                throw new ArgumentNullException(nameof(value));
            }

            using var valueVector = new VectorOfKeyPoint(value);
            NativeMethods.HandleException(
                NativeMethods.core_FileStorage_write_vectorOfKeyPoint(ptr, name, valueVector.CvPtr));
            GC.KeepAlive(this);
        }
Example #7
0
        /// <summary>
        /// Compute the descriptors for a set of keypoints in an image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="keypoints">The input keypoints. Keypoints for which a descriptor cannot be computed are removed.</param>
        /// <param name="descriptors">Copmputed descriptors. Row i is the descriptor for keypoint i.</param>param>
        public virtual void Compute(InputArray image, ref KeyPoint[] keypoints, OutputArray descriptors)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            ThrowIfDisposed();

            using (var keypointsVec = new VectorOfKeyPoint(keypoints))
            {
                NativeMethods.features2d_Feature2D_compute1(ptr, image.CvPtr, keypointsVec.CvPtr, descriptors.CvPtr);
                keypoints = keypointsVec.ToArray();
            }
            GC.KeepAlive(this);
            GC.KeepAlive(image);
            GC.KeepAlive(descriptors);
        }
Example #8
0
        /// <summary>
        /// Compute the descriptors for a set of keypoints in an image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="keypoints">The input keypoints. Keypoints for which a descriptor cannot be computed are removed.</param>
        /// <param name="descriptors">Copmputed descriptors. Row i is the descriptor for keypoint i.</param>param>
        public virtual void Compute(InputArray image, ref KeyPoint[] keypoints, OutputArray descriptors)
        {
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            if (disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }

            using (var keypointsVec = new VectorOfKeyPoint(keypoints))
            {
                NativeMethods.features2d_Feature2D_compute1(ptr, image.CvPtr, keypointsVec.CvPtr, descriptors.CvPtr);
                keypoints = keypointsVec.ToArray();
            }
        }
Example #9
0
        /// <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(nameof(keypoints));
            }
            if (mask == null)
            {
                throw new ArgumentNullException(nameof(mask));
            }
            mask.ThrowIfDisposed();

            using var keypointsVec = new VectorOfKeyPoint(keypoints);
            NativeMethods.HandleException(
                NativeMethods.features2d_KeyPointsFilter_runByPixelsMask(keypointsVec.CvPtr, mask.CvPtr));
            GC.KeepAlive(mask);
            return(keypointsVec.ToArray());
        }
        /// <summary>
        /// Computes an image descriptor using the set visual vocabulary.
        /// </summary>
        /// <param name="image">Image, for which the descriptor is computed.</param>
        /// <param name="keypoints">Keypoints detected in the input image.</param>
        /// <param name="imgDescriptor">Computed output image descriptor.</param>
        public void Compute2(Mat image, ref KeyPoint[] keypoints, Mat imgDescriptor)
        {
            ThrowIfDisposed();
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            if (imgDescriptor == null)
            {
                throw new ArgumentNullException(nameof(imgDescriptor));
            }

            using (var keypointsVec = new VectorOfKeyPoint(keypoints))
            {
                NativeMethods.features2d_BOWImgDescriptorExtractor_compute2(
                    ptr, image.CvPtr, keypointsVec.CvPtr, imgDescriptor.CvPtr);
                keypoints = keypointsVec.ToArray();
            }
            GC.KeepAlive(image);
            GC.KeepAlive(imgDescriptor);
        }
Example #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="img1"></param>
        /// <param name="img2"></param>
        /// <param name="H1to2"></param>
        /// <param name="keypoints1"></param>
        /// <param name="keypoints2"></param>
        /// <param name="repeatability"></param>
        /// <param name="correspCount"></param>
        public static void EvaluateFeatureDetector(
            Mat img1, Mat img2, Mat H1to2,
            ref KeyPoint[] keypoints1, ref KeyPoint[] keypoints2,
            out float repeatability, out int correspCount)
        {
            if (img1 == null)
            {
                throw new ArgumentNullException(nameof(img1));
            }
            if (img2 == null)
            {
                throw new ArgumentNullException(nameof(img2));
            }
            if (H1to2 == null)
            {
                throw new ArgumentNullException(nameof(H1to2));
            }
            if (keypoints1 == null)
            {
                throw new ArgumentNullException(nameof(keypoints1));
            }
            if (keypoints2 == null)
            {
                throw new ArgumentNullException(nameof(keypoints2));
            }

            using (var keypoints1Vec = new VectorOfKeyPoint(keypoints1))
                using (var keypoints2Vec = new VectorOfKeyPoint(keypoints2))
                {
                    NativeMethods.features2d_evaluateFeatureDetector(
                        img1.CvPtr, img2.CvPtr, H1to2.CvPtr,
                        keypoints1Vec.CvPtr, keypoints2Vec.CvPtr,
                        out repeatability, out correspCount);
                    GC.KeepAlive(img1);
                    GC.KeepAlive(img2);
                    GC.KeepAlive(H1to2);
                    keypoints1 = keypoints1Vec.ToArray();
                    keypoints2 = keypoints2Vec.ToArray();
                }
        }
Example #12
0
        /// <summary>
        /// Detect keypoints in an image.
        /// </summary>
        /// <param name="image">The image.</param>
        /// <param name="mask">Mask specifying where to look for keypoints (optional).
        /// Must be a char matrix with non-zero values in the region of interest.</param>
        /// <returns>The detected keypoints.</returns>
        public KeyPoint[] Detect(Mat image, Mat?mask = null)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }
            ThrowIfDisposed();

            image.ThrowIfDisposed();
            try
            {
                using var keyPoints = new VectorOfKeyPoint();
                NativeMethods.HandleException(
                    NativeMethods.features2d_Feature2D_detect_Mat1(ptr, image.CvPtr, keyPoints.CvPtr, Cv2.ToPtr(mask)));
                return(keyPoints.ToArray());
            }
            finally
            {
                GC.KeepAlive(this);
                GC.KeepAlive(image);
                GC.KeepAlive(mask);
            }
        }
Example #13
0
        /// <summary>
        /// Detects keypoints and computes the descriptors
        /// </summary>
        /// <param name="image"></param>
        /// <param name="mask"></param>
        /// <param name="keypoints"></param>
        /// <param name="descriptors"></param>
        /// <param name="useProvidedKeypoints"></param>
        public virtual void DetectAndCompute(
            InputArray image,
            InputArray mask,
            out KeyPoint[] keypoints,
            OutputArray descriptors,
            bool useProvidedKeypoints = false)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(GetType().Name);
            }
            if (image == null)
            {
                throw new ArgumentNullException("image");
            }
            if (descriptors == null)
            {
                throw new ArgumentNullException("descriptors");
            }
            image.ThrowIfDisposed();
            if (mask != null)
            {
                mask.ThrowIfDisposed();
            }

            using (var keypointsVec = new VectorOfKeyPoint())
            {
                NativeMethods.features2d_Feature2D_detectAndCompute(
                    ptr, image.CvPtr, Cv2.ToPtr(mask), keypointsVec.CvPtr, descriptors.CvPtr, useProvidedKeypoints ? 1 : 0);
                keypoints = keypointsVec.ToArray();
            }

            GC.KeepAlive(image);
            GC.KeepAlive(mask);
            descriptors.Fix();
        }