-
-
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.
Add BOWTrainer, BOWKMeansTrainer and BOWImgDescriptorExtractor
- Loading branch information
Showing
13 changed files
with
763 additions
and
2 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
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
66 changes: 66 additions & 0 deletions
66
src/OpenCvSharp/PInvoke/features2d/NativeMethods_features2d_BOW.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,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); | ||
} | ||
} |
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,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> | ||
/// &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 | ||
} | ||
} |
Oops, something went wrong.