Skip to content

Commit

Permalink
Added Feature2D.DetectAndCompute
Browse files Browse the repository at this point in the history
  • Loading branch information
shimat committed Aug 19, 2015
1 parent b2eb0c2 commit 92de424
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 69 deletions.
1 change: 1 addition & 0 deletions src/OpenCvSharp/OpenCvSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<Compile Include="Modules\ml\Enum\SampleTypes.cs" />
<Compile Include="Modules\ml\ParamGrid.cs" />
<Compile Include="Modules\ml\TrainData.cs" />
<Compile Include="PInvoke\features2d\NativeMethods_features2d_Feature2D.cs" />
<Compile Include="PInvoke\features2d\NativeMethods_features2d_AgastFeatureDetector.cs" />
<Compile Include="PInvoke\features2d\NativeMethods_features2d_AKAZE.cs" />
<Compile Include="PInvoke\features2d\NativeMethods_features2d_KAZE.cs" />
Expand Down
35 changes: 1 addition & 34 deletions src/OpenCvSharp/PInvoke/features2d/NativeMethods_features2d.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,6 @@ static partial class NativeMethods
{
// ReSharper disable InconsistentNaming

// FeatureDetector
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr features2d_Feature2D_info(IntPtr obj);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_Feature2D_detect_Mat1(IntPtr detector, IntPtr image, IntPtr keypoints, IntPtr mask);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_Feature2D_detect_Mat2(IntPtr detector, IntPtr[] images, int imageLength, IntPtr keypoints, IntPtr[] mask);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_Feature2D_detect_InputArray(IntPtr detector, IntPtr image, IntPtr keypoints, IntPtr mask);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_Feature2D_compute1(IntPtr obj, IntPtr image, IntPtr keypoints, IntPtr descriptors);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_Feature2D_compute2(
IntPtr detector, IntPtr[] images, int imageLength,
IntPtr keypoints, IntPtr[] descriptors, int descriptorsLength);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr features2d_Ptr_Feature2D_get(IntPtr ptr);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_Ptr_Feature2D_delete(IntPtr ptr);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern int features2d_Feature2D_descriptorSize(IntPtr obj);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern int features2d_Feature2D_descriptorType(IntPtr obj);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern int features2d_Feature2D_defaultNorm(IntPtr obj);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern int features2d_Feature2D_empty(IntPtr obj);

// DenseFeatureDetector
/*
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
Expand All @@ -57,8 +25,7 @@ public static extern IntPtr features2d_DenseFeatureDetector_new(
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_Ptr_DenseFeatureDetector_delete(IntPtr ptr);
*/



[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_drawKeypoints(IntPtr image, KeyPoint[] keypoints, int keypointsLength,
IntPtr outImage, Scalar color, int flags);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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 IntPtr features2d_Ptr_Feature2D_get(IntPtr ptr);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_Ptr_Feature2D_delete(IntPtr ptr);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_Feature2D_detect_Mat1(IntPtr detector, IntPtr image, IntPtr keypoints, IntPtr mask);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_Feature2D_detect_Mat2(IntPtr detector, IntPtr[] images, int imageLength, IntPtr keypoints, IntPtr[] mask);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_Feature2D_detect_InputArray(IntPtr detector, IntPtr image, IntPtr keypoints, IntPtr mask);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_Feature2D_compute1(IntPtr obj, IntPtr image, IntPtr keypoints, IntPtr descriptors);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_Feature2D_compute2(
IntPtr detector, IntPtr[] images, int imageLength,
IntPtr keypoints, IntPtr[] descriptors, int descriptorsLength);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_Feature2D_detectAndCompute(
IntPtr detector, IntPtr image, IntPtr mask,
IntPtr keypoints, IntPtr descriptors, int useProvidedKeypoints);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern int features2d_Feature2D_descriptorSize(IntPtr obj);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern int features2d_Feature2D_descriptorType(IntPtr obj);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern int features2d_Feature2D_defaultNorm(IntPtr obj);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern int features2d_Feature2D_empty(IntPtr obj);
}
}
119 changes: 84 additions & 35 deletions src/OpenCvSharp/modules/features2d/Feature2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,62 @@ protected override void Dispose(bool disposing)
}
}
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public virtual int DescriptorSize
{
get
{
if (disposed)
throw new ObjectDisposedException(GetType().Name);
return NativeMethods.features2d_Feature2D_descriptorSize(ptr);
}
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public virtual int DescriptorType
{
get
{
if (disposed)
throw new ObjectDisposedException(GetType().Name);
return NativeMethods.features2d_Feature2D_descriptorType(ptr);
}
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public virtual int DefaultNorm
{
get
{
if (disposed)
throw new ObjectDisposedException(GetType().Name);
return NativeMethods.features2d_Feature2D_defaultNorm(ptr);
}
}

/// <summary>
/// Return true if detector object is empty
/// </summary>
/// <returns></returns>
public virtual bool Empty
{
get
{
if (disposed)
throw new ObjectDisposedException(GetType().Name);
return NativeMethods.features2d_Feature2D_empty(ptr) != 0;
}
}

/// <summary>
/// Detect keypoints in an image.
Expand Down Expand Up @@ -256,47 +312,40 @@ public virtual void Compute(IEnumerable<Mat> images, ref KeyPoint[][] keypoints,
}

/// <summary>
///
/// </summary>
/// <returns></returns>
public virtual int DescriptorSize()
{
if (disposed)
throw new ObjectDisposedException(GetType().Name);
return NativeMethods.features2d_Feature2D_descriptorSize(ptr);
}

/// <summary>
///
/// Detects keypoints and computes the descriptors
/// </summary>
/// <returns></returns>
public virtual int DescriptorType()
/// <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);
return NativeMethods.features2d_Feature2D_descriptorType(ptr);
}
if (image == null)
throw new ArgumentNullException("image");
if (descriptors == null)
throw new ArgumentNullException("descriptors");
image.ThrowIfDisposed();
if (mask != null)
mask.ThrowIfDisposed();

/// <summary>
///
/// </summary>
/// <returns></returns>
public virtual int DefaultNorm()
{
if (disposed)
throw new ObjectDisposedException(GetType().Name);
return NativeMethods.features2d_Feature2D_defaultNorm(ptr);
}
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();
}

/// <summary>
/// Return true if detector object is empty
/// </summary>
/// <returns></returns>
public virtual bool Empty()
{
if (disposed)
throw new ObjectDisposedException(GetType().Name);
return NativeMethods.features2d_Feature2D_empty(ptr) != 0;
GC.KeepAlive(image);
GC.KeepAlive(mask);
descriptors.Fix();
}
}
}
7 changes: 7 additions & 0 deletions src/OpenCvSharpExtern/features2d_FeatureDetector.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ CVAPI(void) features2d_Feature2D_compute2(
detector->compute(imageVec, *keypoints, descriptorsVec);
}

CVAPI(void) features2d_Feature2D_detectAndCompute(
cv::Feature2D *detector, cv::_InputArray *image, cv::_InputArray *mask,
std::vector<cv::KeyPoint> *keypoints, cv::_OutputArray *descriptors, int useProvidedKeypoints)
{
detector->detectAndCompute(entity(image), entity(mask), *keypoints, *descriptors, useProvidedKeypoints != 0);
}

CVAPI(int) features2d_Feature2D_descriptorSize(cv::Ptr<cv::Feature2D> *obj)
{
return obj->get()->descriptorSize();
Expand Down

0 comments on commit 92de424

Please sign in to comment.