-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/OpenCvSharp/PInvoke/features2d/NativeMethods_features2d_KeyPointsFilter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
#pragma warning disable 1591 | ||
|
||
namespace OpenCvSharp | ||
{ | ||
static partial class NativeMethods | ||
{ | ||
// ReSharper disable InconsistentNaming | ||
|
||
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void features2d_KeyPointsFilter_runByImageBorder( | ||
IntPtr keypoints, Size imageSize, int borderSize); | ||
|
||
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void features2d_KeyPointsFilter_runByKeypointSize( | ||
IntPtr keypoints, float minSize, float maxSize); | ||
|
||
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void features2d_KeyPointsFilter_runByPixelsMask( | ||
IntPtr keypoints, IntPtr mask); | ||
|
||
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void features2d_KeyPointsFilter_removeDuplicated( | ||
IntPtr keypoints); | ||
|
||
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)] | ||
public static extern void features2d_KeyPointsFilter_retainBest( | ||
IntPtr keypoints, int npoints); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
|
||
namespace OpenCvSharp | ||
{ | ||
// ReSharper disable once InconsistentNaming | ||
|
||
/// <summary> | ||
/// A class filters a vector of keypoints. | ||
/// </summary> | ||
public static class KeyPointsFilter | ||
{ | ||
/// <summary> | ||
/// Remove keypoints within borderPixels of an image edge. | ||
/// </summary> | ||
/// <param name="keypoints"></param> | ||
/// <param name="imageSize"></param> | ||
/// <param name="borderSize"></param> | ||
/// <returns></returns> | ||
public static KeyPoint[] RunByImageBorder(IEnumerable<KeyPoint> keypoints, Size imageSize, int borderSize) | ||
{ | ||
if (keypoints == null) | ||
throw new ArgumentNullException("keypoints"); | ||
|
||
using (var keypointsVec = new VectorOfKeyPoint(keypoints)) | ||
{ | ||
NativeMethods.features2d_KeyPointsFilter_runByImageBorder( | ||
keypointsVec.CvPtr, imageSize, borderSize); | ||
return keypointsVec.ToArray(); | ||
} | ||
} | ||
|
||
/// <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("keypoints"); | ||
|
||
using (var keypointsVec = new VectorOfKeyPoint(keypoints)) | ||
{ | ||
NativeMethods.features2d_KeyPointsFilter_runByKeypointSize( | ||
keypointsVec.CvPtr, minSize, maxSize); | ||
return keypointsVec.ToArray(); | ||
} | ||
} | ||
|
||
/// <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("keypoints"); | ||
if (mask == null) | ||
throw new ArgumentNullException("mask"); | ||
mask.ThrowIfDisposed(); | ||
|
||
using (var keypointsVec = new VectorOfKeyPoint(keypoints)) | ||
{ | ||
NativeMethods.features2d_KeyPointsFilter_runByPixelsMask( | ||
keypointsVec.CvPtr, mask.CvPtr); | ||
GC.KeepAlive(mask); | ||
return keypointsVec.ToArray(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Remove duplicated keypoints. | ||
/// </summary> | ||
/// <param name="keypoints"></param> | ||
/// <returns></returns> | ||
public static KeyPoint[] RemoveDuplicated(IEnumerable<KeyPoint> keypoints) | ||
{ | ||
if (keypoints == null) | ||
throw new ArgumentNullException("keypoints"); | ||
|
||
using (var keypointsVec = new VectorOfKeyPoint(keypoints)) | ||
{ | ||
NativeMethods.features2d_KeyPointsFilter_removeDuplicated(keypointsVec.CvPtr); | ||
return keypointsVec.ToArray(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Retain the specified number of the best keypoints (according to the response) | ||
/// </summary> | ||
/// <param name="keypoints"></param> | ||
/// <param name="npoints"></param> | ||
/// <returns></returns> | ||
public static KeyPoint[] RetainBest(IEnumerable<KeyPoint> keypoints, int npoints) | ||
{ | ||
if (keypoints == null) | ||
throw new ArgumentNullException("keypoints"); | ||
|
||
using (var keypointsVec = new VectorOfKeyPoint(keypoints)) | ||
{ | ||
NativeMethods.features2d_KeyPointsFilter_retainBest( | ||
keypointsVec.CvPtr, npoints); | ||
return keypointsVec.ToArray(); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef _CPP_FEATURES2D_KAZE_H_ | ||
#define _CPP_FEATURES2D_KAZE_H_ | ||
|
||
#include "include_opencv.h" | ||
|
||
|
||
CVAPI(void) features2d_KeyPointsFilter_runByImageBorder( | ||
std::vector<cv::KeyPoint> *keypoints, MyCvSize imageSize, int borderSize) | ||
{ | ||
cv::KeyPointsFilter::runByImageBorder(*keypoints, cpp(imageSize), borderSize); | ||
} | ||
|
||
CVAPI(void) features2d_KeyPointsFilter_runByKeypointSize( | ||
std::vector<cv::KeyPoint> *keypoints, float minSize, float maxSize) | ||
{ | ||
cv::KeyPointsFilter::runByKeypointSize(*keypoints, minSize, maxSize); | ||
} | ||
CVAPI(void) features2d_KeyPointsFilter_runByPixelsMask( | ||
std::vector<cv::KeyPoint> *keypoints, cv::Mat *mask) | ||
{ | ||
cv::KeyPointsFilter::runByPixelsMask(*keypoints, *mask); | ||
} | ||
|
||
CVAPI(void) features2d_KeyPointsFilter_removeDuplicated( | ||
std::vector<cv::KeyPoint> *keypoints) | ||
{ | ||
cv::KeyPointsFilter::removeDuplicated(*keypoints); | ||
} | ||
|
||
CVAPI(void) features2d_KeyPointsFilter_retainBest( | ||
std::vector<cv::KeyPoint> *keypoints, int npoints) | ||
{ | ||
cv::KeyPointsFilter::retainBest(*keypoints, npoints); | ||
} | ||
|
||
#endif |