/// <summary> /// Detect keypoints in an image set. /// </summary> /// <param name="images">Image collection.</param> /// <param name="masks">Masks for image set. masks[i] is a mask for images[i].</param> /// <returns>Collection of keypoints detected in an input images. keypoints[i] is a set of keypoints detected in an images[i].</returns> public KeyPoint[][] Detect(IEnumerable<Mat> images, IEnumerable<Mat> masks = null) { if (images == null) throw new ArgumentNullException("images"); Mat[] imagesArray = Util.ToArray(images); IntPtr[] imagesPtr = new IntPtr[imagesArray.Length]; for (int i = 0; i < imagesArray.Length; i++) imagesPtr[i] = imagesArray[i].CvPtr; using (var keypoints = new VectorOfVectorKeyPoint()) { if (masks == null) { NativeMethods.features2d_FeatureDetector_detect( ptr, imagesPtr, imagesArray.Length, keypoints.CvPtr, null); } else { IntPtr[] masksPtr = EnumerableEx.SelectPtrs(masks); if (masksPtr.Length != imagesArray.Length) throw new ArgumentException("masks.Length != images.Length"); NativeMethods.features2d_FeatureDetector_detect( ptr, imagesPtr, imagesArray.Length, keypoints.CvPtr, masksPtr); } return keypoints.ToArray(); } }
/// <summary> /// select the 512 "best description pairs" /// </summary> /// <param name="images">grayscale images set</param> /// <param name="keypoints">set of detected keypoints</param> /// <param name="corrThresh">correlation threshold</param> /// <param name="verbose">print construction information</param> /// <returns>list of best pair indexes</returns> public int[] SelectPairs(IEnumerable<Mat> images, out KeyPoint[][] keypoints, double corrThresh = 0.7, bool verbose = true) { if (images == null) throw new ArgumentNullException("images"); IntPtr[] imagesPtrs = EnumerableEx.SelectPtrs(images); using (var outVec = new VectorOfInt32()) using (var keypointsVec = new VectorOfVectorKeyPoint()) { NativeMethods.features2d_FREAK_selectPairs(ptr, imagesPtrs, imagesPtrs.Length, keypointsVec.CvPtr, corrThresh, verbose ? 1 : 0, outVec.CvPtr); keypoints = keypointsVec.ToArray(); return outVec.ToArray(); } }
/// <summary> /// Compute the descriptors for a keypoints collection detected in image collection. /// </summary> /// <param name="images">Image collection.</param> /// <param name="keypoints">Input keypoints collection. keypoints[i] is keypoints detected in images[i]. /// Keypoints for which a descriptor cannot be computed are removed.</param> /// <param name="descriptors">Descriptor collection. descriptors[i] are descriptors computed for set keypoints[i].</param> public virtual void Compute(IEnumerable<Mat> images, ref KeyPoint[][] keypoints, IEnumerable<Mat> descriptors) { if (disposed) throw new ObjectDisposedException(GetType().Name); if (images == null) throw new ArgumentNullException("images"); if (descriptors == null) throw new ArgumentNullException("descriptors"); IntPtr[] imagesPtrs = EnumerableEx.SelectPtrs(images); IntPtr[] descriptorsPtrs = EnumerableEx.SelectPtrs(descriptors); using (var keypointsVec = new VectorOfVectorKeyPoint(keypoints)) { NativeMethods.features2d_Feature2D_compute2( ptr, imagesPtrs, imagesPtrs.Length, keypointsVec.CvPtr, descriptorsPtrs, descriptorsPtrs.Length); keypoints = keypointsVec.ToArray(); } }