Skip to content

Commit

Permalink
Add BOWTrainer, BOWKMeansTrainer and BOWImgDescriptorExtractor
Browse files Browse the repository at this point in the history
  • Loading branch information
shimat committed Nov 5, 2016
1 parent 89e5185 commit 6a83bed
Show file tree
Hide file tree
Showing 13 changed files with 763 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/OpenCvSharp/OpenCvSharp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
<Compile Include="Modules\core\OutputArrayOfMatList.cs" />
<Compile Include="Modules\core\OutputArrayOfStructList.cs" />
<Compile Include="Modules\features2d\AgastFeatureDetector.cs" />
<Compile Include="Modules\features2d\BOWImgDescriptorExtractor.cs" />
<Compile Include="Modules\features2d\BOWKMeansTrainer.cs" />
<Compile Include="Modules\features2d\BOWTrainer.cs" />
<Compile Include="Modules\features2d\KeyPointsFilter.cs" />
<Compile Include="Modules\features2d\Enum\FASTType.cs" />
<Compile Include="Modules\features2d\Enum\AGASTType.cs" />
Expand Down Expand Up @@ -135,6 +138,7 @@
<Compile Include="Modules\shape\ShapeContextDistanceExtractor.cs" />
<Compile Include="Modules\shape\ShapeDistanceExtractor.cs" />
<Compile Include="PInvoke\core\NativeMethods_core_Algorithm.cs" />
<Compile Include="PInvoke\features2d\NativeMethods_features2d_BOW.cs" />
<Compile Include="PInvoke\features2d\NativeMethods_features2d_KeyPointsFilter.cs" />
<Compile Include="PInvoke\features2d\NativeMethods_features2d_Feature2D.cs" />
<Compile Include="PInvoke\features2d\NativeMethods_features2d_AgastFeatureDetector.cs" />
Expand Down Expand Up @@ -363,6 +367,7 @@
<Compile Include="Vector\VectorOfDMatch.cs" />
<Compile Include="Vector\VectorOfVec6d.cs" />
<Compile Include="Vector\VectorOfVectorDouble.cs" />
<Compile Include="Vector\VectorOfVectorInt.cs" />
<Compile Include="Vector\VectorOfVectorFloat.cs" />
<Compile Include="Vector\VectorOfVectorDMatch.cs" />
<Compile Include="Vector\VectorOfVectorPoint.cs" />
Expand Down
16 changes: 16 additions & 0 deletions src/OpenCvSharp/PInvoke/NativeMethods_stdvector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,22 @@ static partial class NativeMethods
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void vector_DMatch_delete(IntPtr vector);
#endregion
#region vector<int>
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr vector_vector_int_new1();
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr vector_vector_int_new2(IntPtr size);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr vector_vector_int_getSize1(IntPtr vector);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void vector_vector_int_getSize2(IntPtr vector, [In, Out] IntPtr[] size);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr vector_vector_int_getPointer(IntPtr vector);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void vector_vector_int_copy(IntPtr vec, IntPtr[] dst);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void vector_vector_int_delete(IntPtr vector);
#endregion
#region vector<float>
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr vector_vector_float_new1();
Expand Down
66 changes: 66 additions & 0 deletions src/OpenCvSharp/PInvoke/features2d/NativeMethods_features2d_BOW.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using System;
using System.Runtime.InteropServices;

#pragma warning disable 1591

namespace OpenCvSharp
{
static partial class NativeMethods
{
// ReSharper disable InconsistentNaming

// BOWTrainer

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_BOWTrainer_add(IntPtr obj, IntPtr descriptors);

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_BOWTrainer_getDescriptors(IntPtr obj, IntPtr descriptors);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern int features2d_BOWTrainer_descriptorsCount(IntPtr obj);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_BOWTrainer_clear(IntPtr obj);


// BOWKMeansTrainer

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr features2d_BOWKMeansTrainer_new(
int clusterCount, TermCriteria termcrit, int attempts, int flags);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_BOWKMeansTrainer_delete(IntPtr obj);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr features2d_BOWKMeansTrainer_cluster1(IntPtr obj);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr features2d_BOWKMeansTrainer_cluster2(IntPtr obj, IntPtr descriptors);


// BOWImgDescriptorExtractor

[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr features2d_BOWImgDescriptorExtractor_new1(IntPtr dextractor, IntPtr dmatcher);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr features2d_BOWImgDescriptorExtractor_new2(IntPtr dmatcher);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_BOWImgDescriptorExtractor_delete(IntPtr obj);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_BOWImgDescriptorExtractor_setVocabulary(IntPtr obj, IntPtr vocabulary);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern IntPtr features2d_BOWImgDescriptorExtractor_getVocabulary(IntPtr obj);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_BOWImgDescriptorExtractor_compute11(
IntPtr obj, IntPtr image, IntPtr keypoints, IntPtr imgDescriptor,
IntPtr pointIdxsOfClusters, IntPtr descriptors);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_BOWImgDescriptorExtractor_compute12(
IntPtr obj, IntPtr keypointDescriptors,
IntPtr imgDescriptor, IntPtr pointIdxsOfClusters);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern void features2d_BOWImgDescriptorExtractor_compute2(
IntPtr obj, IntPtr image, IntPtr keypoints, IntPtr imgDescriptor);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern int features2d_BOWImgDescriptorExtractor_descriptorSize(IntPtr obj);
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
public static extern int features2d_BOWImgDescriptorExtractor_descriptorType(IntPtr obj);
}
}
137 changes: 137 additions & 0 deletions src/OpenCvSharp/Vector/VectorOfVectorInt.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
using System;
using OpenCvSharp.Util;

namespace OpenCvSharp
{
/// <summary>
///
/// </summary>
internal class VectorOfVectorInt : DisposableCvObject, IStdVector<int[]>
{
/// <summary>
/// Track whether Dispose has been called
/// </summary>
private bool disposed = false;

#region Init and Dispose

/// <summary>
///
/// </summary>
public VectorOfVectorInt()
{
ptr = NativeMethods.vector_vector_int_new1();
}

/// <summary>
///
/// </summary>
/// <param name="size"></param>
public VectorOfVectorInt(int size)
{
if (size < 0)
throw new ArgumentOutOfRangeException(nameof(size));
ptr = NativeMethods.vector_vector_int_new2(new IntPtr(size));
}

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">
/// If disposing equals true, the method has been called directly or indirectly by a user's code. Managed and unmanaged resources can be disposed.
/// If false, the method has been called by the runtime from inside the finalizer and you should not reference other objects. Only unmanaged resources can be disposed.
/// </param>
protected override void Dispose(bool disposing)
{
if (!disposed)
{
try
{
if (IsEnabledDispose)
{
NativeMethods.vector_vector_int_delete(ptr);
}
disposed = true;
}
finally
{
base.Dispose(disposing);
}
}
}

#endregion

#region Properties

/// <summary>
/// vector.size()
/// </summary>
public int Size1
{
get { return NativeMethods.vector_vector_int_getSize1(ptr).ToInt32(); }
}

public int Size
{
get { return Size1; }
}

/// <summary>
/// vector[i].size()
/// </summary>
public long[] Size2
{
get
{
int size1 = Size1;
IntPtr[] size2Org = new IntPtr[size1];
NativeMethods.vector_vector_int_getSize2(ptr, size2Org);
long[] size2 = new long[size1];
for (int i = 0; i < size1; i++)
{
size2[i] = size2Org[i].ToInt64();
}
return size2;
}
}


/// <summary>
/// &amp;vector[0]
/// </summary>
public IntPtr ElemPtr
{
get { return NativeMethods.vector_vector_int_getPointer(ptr); }
}

#endregion

#region Methods

/// <summary>
/// Converts std::vector to managed array
/// </summary>
/// <returns></returns>
public int[][] ToArray()
{
int size1 = Size1;
if (size1 == 0)
return new int[0][];
long[] size2 = Size2;

var ret = new int[size1][];
for (int i = 0; i < size1; i++)
{
ret[i] = new int[size2[i]];
}
using (var retPtr = new ArrayAddress2<int>(ret))
{
NativeMethods.vector_vector_int_copy(ptr, retPtr);
}
return ret;
}

#endregion
}
}
Loading

0 comments on commit 6a83bed

Please sign in to comment.