/// <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> /// <param name="pointIdxsOfClusters">pointIdxsOfClusters Indices of keypoints that belong to the cluster. /// This means that pointIdxsOfClusters[i] are keypoint indices that belong to the i -th cluster(word of vocabulary) returned if it is non-zero.</param> /// <param name="descriptors">Descriptors of the image keypoints that are returned if they are non-zero.</param> public void Compute(Mat image, out KeyPoint[] keypoints, Mat imgDescriptor, out int[][] pointIdxsOfClusters, Mat descriptors = null) { if (IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (image == null) { throw new ArgumentNullException(nameof(image)); } if (imgDescriptor == null) { throw new ArgumentNullException(nameof(imgDescriptor)); } using (var keypointsVec = new VectorOfKeyPoint()) using (var pointIdxsOfClustersVec = new VectorOfVectorInt()) { NativeMethods.features2d_BOWImgDescriptorExtractor_compute1(ptr, image.CvPtr, keypointsVec.CvPtr, imgDescriptor.CvPtr, pointIdxsOfClustersVec.CvPtr, Cv2.ToPtr(descriptors)); keypoints = keypointsVec.ToArray(); pointIdxsOfClusters = pointIdxsOfClustersVec.ToArray(); } GC.KeepAlive(image); GC.KeepAlive(imgDescriptor); GC.KeepAlive(descriptors); }
/// <summary> /// /// </summary> /// <returns></returns> public KeyPoint[] ReadKeyPoints() { using (var valueVector = new VectorOfKeyPoint()) { NativeMethods.core_FileNode_read_vectorOfKeyPoint(ptr, valueVector.CvPtr); return(valueVector.ToArray()); } }
/// <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(Mat image, ref KeyPoint[] keypoints, Mat descriptors) { if (image == null) { throw new ArgumentNullException("image"); } using (var keypointsVec = new VectorOfKeyPoint(keypoints)) { NativeMethods.features2d_Feature2D_compute(ptr, image.CvPtr, keypointsVec.CvPtr, descriptors.CvPtr); keypoints = keypointsVec.ToArray(); } }
/// <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("image"); } using (var keypoints = new VectorOfKeyPoint()) { NativeMethods.features2d_FeatureDetector_detect(ptr, image.CvPtr, keypoints.CvPtr, Cv2.ToPtr(mask)); return(keypoints.ToArray()); } }
/// <summary> /// detects corners using FAST algorithm by E. Rosten /// </summary> /// <param name="image"></param> /// <param name="keypoints"></param> /// <param name="threshold"></param> /// <param name="nonmaxSupression"></param> /// <param name="type"></param> public static void FASTX(InputArray image, out KeyPoint[] keypoints, int threshold, bool nonmaxSupression, int type) { if (image == null) { throw new ArgumentNullException(nameof(image)); } image.ThrowIfDisposed(); using (var kp = new VectorOfKeyPoint()) { NativeMethods.features2d_FASTX(image.CvPtr, kp.CvPtr, threshold, nonmaxSupression ? 1 : 0, type); keypoints = kp.ToArray(); } }
/// <summary> /// Compute the BRISK features on an image /// </summary> /// <param name="image"></param> /// <param name="mask"></param> /// <returns></returns> public KeyPoint[] Run(InputArray image, InputArray mask = null) { ThrowIfDisposed(); if (image == null) { throw new ArgumentNullException("image"); } image.ThrowIfDisposed(); using (VectorOfKeyPoint keyPointsVec = new VectorOfKeyPoint()) { NativeMethods.features2d_BRISK_run1(ptr, image.CvPtr, Cv2.ToPtr(mask), keyPointsVec.CvPtr); return(keyPointsVec.ToArray()); } }
/// <summary> /// 高速なマルチスケール Hesian 検出器を用いて keypoint を検出します. /// </summary> /// <param name="img"></param> /// <param name="mask"></param> /// <returns></returns> #else /// <summary> /// detects keypoints using fast multi-scale Hessian detector /// </summary> /// <param name="img"></param> /// <param name="mask"></param> /// <returns></returns> #endif public KeyPoint[] Run(InputArray img, Mat mask) { ThrowIfDisposed(); if (img == null) { throw new ArgumentNullException("img"); } img.ThrowIfDisposed(); using (VectorOfKeyPoint keypointsVec = new VectorOfKeyPoint()) { NativeMethods.nonfree_SURF_run1(ptr, img.CvPtr, Cv2.ToPtr(mask), keypointsVec.CvPtr); return(keypointsVec.ToArray()); } }
/// <summary> /// StarDetectorアルゴリズムによりキーポイントを取得する /// </summary> /// <param name="image">8ビット グレースケールの入力画像</param> /// <returns></returns> #else /// <summary> /// Retrieves keypoints using the StarDetector algorithm. /// </summary> /// <param name="image">The input 8-bit grayscale image</param> /// <returns></returns> #endif public KeyPoint[] Run(Mat image) { if (image == null) { throw new ArgumentNullException("image"); } image.ThrowIfDisposed(); IntPtr keypoints; NativeMethods.features2d_StarDetector_detect(ptr, image.CvPtr, out keypoints); using (VectorOfKeyPoint keypointsVec = new VectorOfKeyPoint(keypoints)) { return(keypointsVec.ToArray()); } }
/// <summary> /// keypoint を検出し,その SURF ディスクリプタを計算します.[useProvidedKeypoints = true] /// </summary> /// <param name="img"></param> /// <param name="mask"></param> /// <param name="keypoints"></param> /// <param name="descriptors"></param> /// <param name="useProvidedKeypoints"></param> #else /// <summary> /// detects keypoints and computes the SURF descriptors for them. [useProvidedKeypoints = true] /// </summary> /// <param name="img"></param> /// <param name="mask"></param> /// <param name="keypoints"></param> /// <param name="descriptors"></param> /// <param name="useProvidedKeypoints"></param> #endif public void Run(InputArray img, InputArray mask, out KeyPoint[] keypoints, out float[] descriptors, bool useProvidedKeypoints = false) { ThrowIfDisposed(); if (img == null) { throw new ArgumentNullException("img"); } img.ThrowIfDisposed(); using (VectorOfKeyPoint keypointsVec = new VectorOfKeyPoint()) using (VectorOfFloat descriptorsVec = new VectorOfFloat()) { NativeMethods.nonfree_SURF_run2_vector(ptr, img.CvPtr, Cv2.ToPtr(mask), keypointsVec.CvPtr, descriptorsVec.CvPtr, useProvidedKeypoints ? 1 : 0); keypoints = keypointsVec.ToArray(); descriptors = descriptorsVec.ToArray(); } }
/// <summary> /// /// </summary> /// <param name="gaussPyr"></param> /// <param name="dogPyr"></param> /// <returns></returns> public KeyPoint[] FindScaleSpaceExtrema(IEnumerable <Mat> gaussPyr, IEnumerable <Mat> dogPyr) { ThrowIfDisposed(); if (gaussPyr == null) { throw new ArgumentNullException("gaussPyr"); } if (dogPyr == null) { throw new ArgumentNullException("dogPyr"); } IntPtr[] gaussPyrPtrs = EnumerableEx.SelectPtrs(gaussPyr); IntPtr[] dogPyrPtrs = EnumerableEx.SelectPtrs(dogPyr); using (VectorOfKeyPoint keyPointsVec = new VectorOfKeyPoint()) { NativeMethods.nonfree_SIFT_findScaleSpaceExtrema(ptr, gaussPyrPtrs, gaussPyrPtrs.Length, dogPyrPtrs, dogPyrPtrs.Length, keyPointsVec.CvPtr); return(keyPointsVec.ToArray()); } }
/// <summary> /// keypoint を検出し,その SURF ディスクリプタを計算します.[useProvidedKeypoints = true] /// </summary> /// <param name="img"></param> /// <param name="mask"></param> /// <param name="keypoints"></param> /// <param name="descriptors"></param> /// <param name="useProvidedKeypoints"></param> #else /// <summary> /// detects keypoints and computes the SURF descriptors for them. [useProvidedKeypoints = true] /// </summary> /// <param name="img"></param> /// <param name="mask"></param> /// <param name="keypoints"></param> /// <param name="descriptors"></param> /// <param name="useProvidedKeypoints"></param> #endif public void Run(InputArray img, InputArray mask, out KeyPoint[] keypoints, OutputArray descriptors, bool useProvidedKeypoints = false) { ThrowIfDisposed(); if (img == null) { throw new ArgumentNullException(nameof(img)); } if (descriptors == null) { throw new ArgumentNullException(nameof(descriptors)); } img.ThrowIfDisposed(); descriptors.ThrowIfNotReady(); using (VectorOfKeyPoint keypointsVec = new VectorOfKeyPoint()) { NativeMethods.nonfree_SURF_run2_OutputArray(ptr, img.CvPtr, Cv2.ToPtr(mask), keypointsVec.CvPtr, descriptors.CvPtr, useProvidedKeypoints ? 1 : 0); keypoints = keypointsVec.ToArray(); } }
/// <summary> /// Compute the BRISK features and descriptors on an image /// </summary> /// <param name="image"></param> /// <param name="mask"></param> /// <param name="keyPoints"></param> /// <param name="descriptors"></param> /// <param name="useProvidedKeypoints"></param> public void Run(InputArray image, InputArray mask, out KeyPoint[] keyPoints, OutputArray descriptors, bool useProvidedKeypoints = false) { ThrowIfDisposed(); if (image == null) { throw new ArgumentNullException("image"); } if (descriptors == null) { throw new ArgumentNullException("descriptors"); } image.ThrowIfDisposed(); descriptors.ThrowIfNotReady(); using (VectorOfKeyPoint keyPointsVec = new VectorOfKeyPoint()) { NativeMethods.features2d_BRISK_run2(ptr, image.CvPtr, Cv2.ToPtr(mask), keyPointsVec.CvPtr, descriptors.CvPtr, useProvidedKeypoints ? 1 : 0); keyPoints = keyPointsVec.ToArray(); } descriptors.Fix(); }
/// <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, out KeyPoint[] keypoints, Mat imgDescriptor) { if (IsDisposed) { throw new ObjectDisposedException(GetType().Name); } if (image == null) { throw new ArgumentNullException(nameof(image)); } if (imgDescriptor == null) { throw new ArgumentNullException(nameof(imgDescriptor)); } using (var keypointsVec = new VectorOfKeyPoint()) { NativeMethods.features2d_BOWImgDescriptorExtractor_compute2( ptr, image.CvPtr, keypointsVec.CvPtr, imgDescriptor.CvPtr); keypoints = keypointsVec.ToArray(); } GC.KeepAlive(image); GC.KeepAlive(imgDescriptor); }