Skip to content

Commit 12d363d

Browse files
authored
Merge pull request #2034 from shimat/feature/2011-features-xfeatures2d-coverage
features/xfeatures2d: close all API coverage gaps from issue #2011
2 parents d59f261 + b8d3517 commit 12d363d

83 files changed

Lines changed: 5999 additions & 18 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/OpenCvSharp/Cv2/Cv2_features.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,67 @@ public static KeyPoint[] AGAST(InputArray image, int threshold, bool nonmaxSuppr
6666
return vector.ToArray();
6767
}
6868

69+
/// <summary>
70+
/// GMS (Grid-based Motion Statistics) feature matching strategy.
71+
/// </summary>
72+
/// <param name="size1">Input size of image1.</param>
73+
/// <param name="size2">Input size of image2.</param>
74+
/// <param name="keypoints1">Input keypoints of image1.</param>
75+
/// <param name="keypoints2">Input keypoints of image2.</param>
76+
/// <param name="matches1To2">Input 1-nearest neighbor matches.</param>
77+
/// <param name="withRotation">Take rotation transformation into account.</param>
78+
/// <param name="withScale">Take scale transformation into account.</param>
79+
/// <param name="thresholdFactor">The higher, the less matches.</param>
80+
/// <returns>Matches returned by the GMS matching strategy.</returns>
81+
public static DMatch[] MatchGMS(
82+
Size size1, Size size2,
83+
IEnumerable<KeyPoint> keypoints1, IEnumerable<KeyPoint> keypoints2,
84+
IEnumerable<DMatch> matches1To2,
85+
bool withRotation = false, bool withScale = false, double thresholdFactor = 6.0)
86+
{
87+
ArgumentNullException.ThrowIfNull(keypoints1);
88+
ArgumentNullException.ThrowIfNull(keypoints2);
89+
ArgumentNullException.ThrowIfNull(matches1To2);
90+
91+
using var keypoints1Vec = new StdVector<KeyPoint>(keypoints1);
92+
using var keypoints2Vec = new StdVector<KeyPoint>(keypoints2);
93+
using var matches1To2Vec = new StdVector<DMatch>(matches1To2);
94+
using var matchesGMSVec = new StdVector<DMatch>();
95+
NativeMethods.HandleException(
96+
NativeMethods.xfeatures2d_matchGMS(
97+
size1, size2, keypoints1Vec.CvPtr, keypoints2Vec.CvPtr, matches1To2Vec.CvPtr, matchesGMSVec.CvPtr,
98+
withRotation ? 1 : 0, withScale ? 1 : 0, thresholdFactor));
99+
return matchesGMSVec.ToArray();
100+
}
101+
102+
/// <summary>
103+
/// LOGOS (Local geometric support for high-outlier spatial verification) feature matching strategy.
104+
/// </summary>
105+
/// <param name="keypoints1">Input keypoints of image1.</param>
106+
/// <param name="keypoints2">Input keypoints of image2.</param>
107+
/// <param name="nn1">Index to the closest BoW centroid for each descriptors of image1.</param>
108+
/// <param name="nn2">Index to the closest BoW centroid for each descriptors of image2.</param>
109+
/// <returns>Matches returned by the LOGOS matching strategy.</returns>
110+
public static DMatch[] MatchLOGOS(
111+
IEnumerable<KeyPoint> keypoints1, IEnumerable<KeyPoint> keypoints2,
112+
IEnumerable<int> nn1, IEnumerable<int> nn2)
113+
{
114+
ArgumentNullException.ThrowIfNull(keypoints1);
115+
ArgumentNullException.ThrowIfNull(keypoints2);
116+
ArgumentNullException.ThrowIfNull(nn1);
117+
ArgumentNullException.ThrowIfNull(nn2);
118+
119+
using var keypoints1Vec = new StdVector<KeyPoint>(keypoints1);
120+
using var keypoints2Vec = new StdVector<KeyPoint>(keypoints2);
121+
using var nn1Vec = new StdVector<int>(nn1);
122+
using var nn2Vec = new StdVector<int>(nn2);
123+
using var matches1To2Vec = new StdVector<DMatch>();
124+
NativeMethods.HandleException(
125+
NativeMethods.xfeatures2d_matchLOGOS(
126+
keypoints1Vec.CvPtr, keypoints2Vec.CvPtr, nn1Vec.CvPtr, nn2Vec.CvPtr, matches1To2Vec.CvPtr));
127+
return matches1To2Vec.ToArray();
128+
}
129+
69130
/// <summary>
70131
/// Draw keypoints.
71132
/// </summary>

src/OpenCvSharp/Cv2/Cv2_imgproc.cs

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,67 @@ public static Point2f[] GoodFeaturesToTrack(InputArray src,
610610
return vector.ToArray();
611611
}
612612

613+
/// <summary>
614+
/// finds the strong enough corners where the cornerMinEigenVal() or cornerHarris() report the local maxima
615+
/// </summary>
616+
/// <param name="src">Input 8-bit or floating-point 32-bit, single-channel image.</param>
617+
/// <param name="maxCorners">Maximum number of corners to return. If there are more corners than are found,
618+
/// the strongest of them is returned.</param>
619+
/// <param name="qualityLevel">Parameter characterizing the minimal accepted quality of image corners.</param>
620+
/// <param name="minDistance">Minimum possible Euclidean distance between the returned corners.</param>
621+
/// <param name="mask">Optional region of interest. If the image is not empty
622+
/// (it needs to have the type CV_8UC1 and the same size as image ), it specifies the region
623+
/// in which the corners are detected.</param>
624+
/// <param name="blockSize">Size of an average block for computing a derivative covariation matrix over each pixel neighborhood.</param>
625+
/// <param name="gradientSize">Aperture parameter for the Sobel operator used for derivatives computation.</param>
626+
/// <param name="useHarrisDetector">Parameter indicating whether to use a Harris detector</param>
627+
/// <param name="k">Free parameter of the Harris detector.</param>
628+
/// <returns>Output vector of detected corners.</returns>
629+
public static Point2f[] GoodFeaturesToTrack(InputArray src,
630+
int maxCorners, double qualityLevel, double minDistance,
631+
InputArray mask, int blockSize, int gradientSize, bool useHarrisDetector, double k)
632+
{
633+
using var vector = new StdVector<Point2f>();
634+
NativeMethods.HandleException(
635+
NativeMethods.imgproc_goodFeaturesToTrack_gradientSize(src.Proxy, vector.CvPtr, maxCorners, qualityLevel,
636+
minDistance, mask.Proxy, blockSize, gradientSize, useHarrisDetector ? 1 : 0, k));
637+
GC.KeepAlive(src.Source);
638+
GC.KeepAlive(mask.Source);
639+
return vector.ToArray();
640+
}
641+
642+
/// <summary>
643+
/// Same as GoodFeaturesToTrack, but returns also quality measure of the detected corners.
644+
/// </summary>
645+
/// <param name="src">Input 8-bit or floating-point 32-bit, single-channel image.</param>
646+
/// <param name="maxCorners">Maximum number of corners to return. If there are more corners than are found,
647+
/// the strongest of them is returned.</param>
648+
/// <param name="qualityLevel">Parameter characterizing the minimal accepted quality of image corners.</param>
649+
/// <param name="minDistance">Minimum possible Euclidean distance between the returned corners.</param>
650+
/// <param name="mask">Region of interest. If the image is not empty
651+
/// (it needs to have the type CV_8UC1 and the same size as image ), it specifies the region
652+
/// in which the corners are detected.</param>
653+
/// <param name="cornersQuality">Output vector of quality measure of the detected corners.</param>
654+
/// <param name="blockSize">Size of an average block for computing a derivative covariation matrix over each pixel neighborhood.</param>
655+
/// <param name="gradientSize">Aperture parameter for the Sobel operator used for derivatives computation.</param>
656+
/// <param name="useHarrisDetector">Parameter indicating whether to use a Harris detector</param>
657+
/// <param name="k">Free parameter of the Harris detector.</param>
658+
/// <returns>Output vector of detected corners.</returns>
659+
public static Point2f[] GoodFeaturesToTrackWithQuality(InputArray src,
660+
int maxCorners, double qualityLevel, double minDistance,
661+
InputArray mask, OutputArray cornersQuality, int blockSize = 3, int gradientSize = 3,
662+
bool useHarrisDetector = false, double k = 0.04)
663+
{
664+
using var vector = new StdVector<Point2f>();
665+
NativeMethods.HandleException(
666+
NativeMethods.imgproc_goodFeaturesToTrackWithQuality(src.Proxy, vector.CvPtr, maxCorners, qualityLevel,
667+
minDistance, mask.Proxy, cornersQuality.Proxy, blockSize, gradientSize, useHarrisDetector ? 1 : 0, k));
668+
GC.KeepAlive(src.Source);
669+
GC.KeepAlive(mask.Source);
670+
GC.KeepAlive(cornersQuality.Source);
671+
return vector.ToArray();
672+
}
673+
613674
/// <summary>
614675
/// Finds lines in a binary image using standard Hough transform.
615676
/// </summary>

src/OpenCvSharp/Internal/PInvoke/NativeMethods/NativeMethods_stdvector.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,18 @@ static partial class NativeMethods
272272
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
273273
public static partial void vector_DMatch_delete(IntPtr vector);
274274
#endregion
275+
#region interop::EllipticKeyPoint
276+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
277+
public static partial IntPtr vector_EllipticKeyPoint_new1();
278+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
279+
public static partial IntPtr vector_EllipticKeyPoint_new3([In] XFeatures2D.EllipticKeyPoint[] data, nuint dataLength);
280+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
281+
public static partial nuint vector_EllipticKeyPoint_getSize(OpenCvSafeHandle vector);
282+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
283+
public static partial IntPtr vector_EllipticKeyPoint_getPointer(OpenCvSafeHandle vector);
284+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
285+
public static partial void vector_EllipticKeyPoint_delete(IntPtr vector);
286+
#endregion
275287
#region cv::Mat
276288
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
277289
public static partial IntPtr vector_Mat_new1();

src/OpenCvSharp/Internal/PInvoke/NativeMethods/NativeMethods_xfeatures2d.cs

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ static partial class NativeMethods
1313
// BriefDescriptorExtractor
1414

1515
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
16-
public static partial ExceptionStatus xfeatures2d_BriefDescriptorExtractor_create(int bytes, out IntPtr returnValue);
16+
public static partial ExceptionStatus xfeatures2d_BriefDescriptorExtractor_create(int bytes, int useOrientation, out IntPtr returnValue);
1717

1818
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
1919
public static partial ExceptionStatus xfeatures2d_Ptr_BriefDescriptorExtractor_delete(IntPtr obj);
@@ -33,6 +33,16 @@ static partial class NativeMethods
3333
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
3434
public static partial ExceptionStatus xfeatures2d_Ptr_BriefDescriptorExtractor_get(IntPtr ptr, out IntPtr returnValue);
3535

36+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
37+
public static partial ExceptionStatus xfeatures2d_BriefDescriptorExtractor_setDescriptorSize(OpenCvSafeHandle obj, int bytes);
38+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
39+
public static partial ExceptionStatus xfeatures2d_BriefDescriptorExtractor_getDescriptorSize(OpenCvSafeHandle obj, out int returnValue);
40+
41+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
42+
public static partial ExceptionStatus xfeatures2d_BriefDescriptorExtractor_setUseOrientation(OpenCvSafeHandle obj, int useOrientation);
43+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
44+
public static partial ExceptionStatus xfeatures2d_BriefDescriptorExtractor_getUseOrientation(OpenCvSafeHandle obj, out int returnValue);
45+
3646

3747
// FREAK
3848

@@ -47,18 +57,63 @@ public static partial ExceptionStatus xfeatures2d_FREAK_create(int orientationNo
4757
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
4858
public static partial ExceptionStatus xfeatures2d_Ptr_FREAK_get(IntPtr ptr, out IntPtr returnValue);
4959

60+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
61+
public static partial ExceptionStatus xfeatures2d_FREAK_setOrientationNormalized(OpenCvSafeHandle obj, int val);
62+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
63+
public static partial ExceptionStatus xfeatures2d_FREAK_getOrientationNormalized(OpenCvSafeHandle obj, out int returnValue);
64+
65+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
66+
public static partial ExceptionStatus xfeatures2d_FREAK_setScaleNormalized(OpenCvSafeHandle obj, int val);
67+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
68+
public static partial ExceptionStatus xfeatures2d_FREAK_getScaleNormalized(OpenCvSafeHandle obj, out int returnValue);
69+
70+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
71+
public static partial ExceptionStatus xfeatures2d_FREAK_setPatternScale(OpenCvSafeHandle obj, double val);
72+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
73+
public static partial ExceptionStatus xfeatures2d_FREAK_getPatternScale(OpenCvSafeHandle obj, out double returnValue);
74+
75+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
76+
public static partial ExceptionStatus xfeatures2d_FREAK_setNOctaves(OpenCvSafeHandle obj, int val);
77+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
78+
public static partial ExceptionStatus xfeatures2d_FREAK_getNOctaves(OpenCvSafeHandle obj, out int returnValue);
79+
5080
// StarDetector
5181
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
5282
public static partial ExceptionStatus xfeatures2d_StarDetector_create(
5383
int maxSize, int responseThreshold,
54-
int lineThresholdProjected, int lineThresholdBinarized, int suppressNonmaxSize,
84+
int lineThresholdProjected, int lineThresholdBinarized, int suppressNonmaxSize,
5585
out IntPtr returnValue);
5686
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
5787
public static partial ExceptionStatus xfeatures2d_Ptr_StarDetector_delete(IntPtr ptr);
5888

5989
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
6090
public static partial ExceptionStatus xfeatures2d_Ptr_StarDetector_get(IntPtr ptr, out IntPtr returnValue);
6191

92+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
93+
public static partial ExceptionStatus xfeatures2d_StarDetector_setMaxSize(OpenCvSafeHandle obj, int val);
94+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
95+
public static partial ExceptionStatus xfeatures2d_StarDetector_getMaxSize(OpenCvSafeHandle obj, out int returnValue);
96+
97+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
98+
public static partial ExceptionStatus xfeatures2d_StarDetector_setResponseThreshold(OpenCvSafeHandle obj, int val);
99+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
100+
public static partial ExceptionStatus xfeatures2d_StarDetector_getResponseThreshold(OpenCvSafeHandle obj, out int returnValue);
101+
102+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
103+
public static partial ExceptionStatus xfeatures2d_StarDetector_setLineThresholdProjected(OpenCvSafeHandle obj, int val);
104+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
105+
public static partial ExceptionStatus xfeatures2d_StarDetector_getLineThresholdProjected(OpenCvSafeHandle obj, out int returnValue);
106+
107+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
108+
public static partial ExceptionStatus xfeatures2d_StarDetector_setLineThresholdBinarized(OpenCvSafeHandle obj, int val);
109+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
110+
public static partial ExceptionStatus xfeatures2d_StarDetector_getLineThresholdBinarized(OpenCvSafeHandle obj, out int returnValue);
111+
112+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
113+
public static partial ExceptionStatus xfeatures2d_StarDetector_setSuppressNonmaxSize(OpenCvSafeHandle obj, int val);
114+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
115+
public static partial ExceptionStatus xfeatures2d_StarDetector_getSuppressNonmaxSize(OpenCvSafeHandle obj, out int returnValue);
116+
62117

63118
// LUCID
64119

@@ -71,6 +126,16 @@ public static partial ExceptionStatus xfeatures2d_StarDetector_create(
71126
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
72127
public static partial ExceptionStatus xfeatures2d_Ptr_LUCID_get(IntPtr ptr, out IntPtr returnValue);
73128

129+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
130+
public static partial ExceptionStatus xfeatures2d_LUCID_setLucidKernel(OpenCvSafeHandle obj, int val);
131+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
132+
public static partial ExceptionStatus xfeatures2d_LUCID_getLucidKernel(OpenCvSafeHandle obj, out int returnValue);
133+
134+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
135+
public static partial ExceptionStatus xfeatures2d_LUCID_setBlurKernel(OpenCvSafeHandle obj, int val);
136+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
137+
public static partial ExceptionStatus xfeatures2d_LUCID_getBlurKernel(OpenCvSafeHandle obj, out int returnValue);
138+
74139

75140
// LATCH
76141

@@ -84,6 +149,26 @@ public static partial ExceptionStatus xfeatures2d_LATCH_create(
84149
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
85150
public static partial ExceptionStatus xfeatures2d_Ptr_LATCH_get(IntPtr ptr, out IntPtr returnValue);
86151

152+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
153+
public static partial ExceptionStatus xfeatures2d_LATCH_setBytes(OpenCvSafeHandle obj, int val);
154+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
155+
public static partial ExceptionStatus xfeatures2d_LATCH_getBytes(OpenCvSafeHandle obj, out int returnValue);
156+
157+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
158+
public static partial ExceptionStatus xfeatures2d_LATCH_setRotationInvariance(OpenCvSafeHandle obj, int val);
159+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
160+
public static partial ExceptionStatus xfeatures2d_LATCH_getRotationInvariance(OpenCvSafeHandle obj, out int returnValue);
161+
162+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
163+
public static partial ExceptionStatus xfeatures2d_LATCH_setHalfSSDsize(OpenCvSafeHandle obj, int val);
164+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
165+
public static partial ExceptionStatus xfeatures2d_LATCH_getHalfSSDsize(OpenCvSafeHandle obj, out int returnValue);
166+
167+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
168+
public static partial ExceptionStatus xfeatures2d_LATCH_setSigma(OpenCvSafeHandle obj, double val);
169+
[LibraryImport(DllExtern), UnmanagedCallConv(CallConvs = [typeof(CallConvCdecl)])]
170+
public static partial ExceptionStatus xfeatures2d_LATCH_getSigma(OpenCvSafeHandle obj, out double returnValue);
171+
87172

88173
// SURF
89174

0 commit comments

Comments
 (0)