Skip to content

Commit 67dcd6a

Browse files
committed
Added CascadeClassifier_GPU
1 parent d697ba5 commit 67dcd6a

15 files changed

+413
-79
lines changed

nuget/OpenCvSharp-AnyCPU.nupkg

-120 Bytes
Binary file not shown.

nuget/OpenCvSharp-AnyCPU.nuspec

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>OpenCvSharp-AnyCPU</id>
5-
<version>2.4.9.20140831</version>
5+
<version>2.4.9.20140901</version>
66
<title>OpenCvSharp</title>
77
<authors>shimat</authors>
88
<licenseUrl>http://opensource.org/licenses/BSD-3-Clause</licenseUrl>
@@ -11,7 +11,8 @@
1111
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1212
<description>OpenCV wrapper for .NET Framework</description>
1313
<releaseNotes>- Fixed many bugs
14-
- Added CLAHE</releaseNotes>
14+
- Added CLAHE
15+
- Removed GC.AddMemoryPressure to improve multiprocessing performance</releaseNotes>
1516
<copyright>Copyright 2008-2014</copyright>
1617
<tags>Image Processing OpenCV Wrapper FFI</tags>
1718
<frameworkAssemblies>

nuget/OpenCvSharp-WithoutDll.nupkg

-124 Bytes
Binary file not shown.

nuget/OpenCvSharp-WithoutDll.nuspec

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22
<package xmlns="http://schemas.microsoft.com/packaging/2011/08/nuspec.xsd">
33
<metadata>
44
<id>OpenCvSharp-WithoutDll</id>
5-
<version>2.4.9.20140831</version>
5+
<version>2.4.9.20140901</version>
66
<title>OpenCvSharp (without DLLs)</title>
77
<authors>shimat</authors>
88
<licenseUrl>http://opensource.org/licenses/BSD-3-Clause</licenseUrl>
99
<projectUrl>https://github.com/shimat/opencvsharp</projectUrl>
1010
<iconUrl>https://raw.githubusercontent.com/shimat/opencvsharp/master/nuget/icon/lenna-icon.png</iconUrl>
1111
<requireLicenseAcceptance>false</requireLicenseAcceptance>
1212
<description>OpenCV wrapper for .NET Framework</description>
13-
<releaseNotes>- Fixed many bugs
14-
- Added CLAHE</releaseNotes>
13+
<releaseNotes>- Fixed many bugs
14+
- Added CLAHE
15+
- Removed GC.AddMemoryPressure to improve multiprocessing performance</releaseNotes>
1516
<copyright>Copyright 2008-2014</copyright>
1617
<tags>Image Processing OpenCV Wrapper FFI</tags>
1718
<frameworkAssemblies>

src/OpenCvSharp.CPlusPlus/OpenCvSharp.CPlusPlus.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
<Compile Include="modules\flann\FlannDistance.cs" />
104104
<Compile Include="Cv2\Cv2_gpu.cs" />
105105
<Compile Include="modules\gpu\DisposableGpuObject.cs" />
106+
<Compile Include="modules\gpu\CascadeClassifier_GPU.cs" />
106107
<Compile Include="modules\gpu\Stream.cs" />
107108
<Compile Include="modules\gpu\Enum\CudaMemAllocType.cs" />
108109
<Compile Include="modules\gpu\DescriptorFormat.cs" />

src/OpenCvSharp.CPlusPlus/PInvoke/NativeMethods_gpu.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,45 @@ public static extern void gpu_Stream_enqueueHostCallback(
202202

203203
#endregion
204204

205+
#region CascadeClassifier_GPU
206+
207+
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
208+
public static extern void gpu_CascadeClassifier_GPU_delete(IntPtr obj);
209+
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
210+
public static extern IntPtr gpu_CascadeClassifier_GPU_new1();
211+
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
212+
public static extern IntPtr gpu_CascadeClassifier_GPU_new2(string filename);
213+
214+
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
215+
public static extern int gpu_CascadeClassifier_GPU_empty(IntPtr obj);
216+
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
217+
public static extern int gpu_CascadeClassifier_GPU_load(IntPtr obj, string filename);
218+
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
219+
public static extern void gpu_CascadeClassifier_GPU_release(IntPtr obj);
220+
221+
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
222+
public static extern int gpu_CascadeClassifier_GPU_detectMultiScale1(IntPtr obj,
223+
IntPtr image, IntPtr objectsBuf, double scaleFactor, int minNeighbors, CvSize minSize);
224+
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
225+
public static extern int gpu_CascadeClassifier_GPU_detectMultiScale2(IntPtr obj,
226+
IntPtr image, IntPtr objectsBuf, CvSize maxObjectSize, CvSize minSize, double scaleFactor,
227+
int minNeighbors);
228+
229+
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
230+
public static extern int gpu_CascadeClassifier_GPU_findLargestObject_get(IntPtr obj);
231+
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
232+
public static extern void gpu_CascadeClassifier_GPU_findLargestObject_set(IntPtr obj, int value);
233+
234+
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
235+
public static extern int gpu_CascadeClassifier_GPU_visualizeInPlace_get(IntPtr obj);
236+
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
237+
public static extern void gpu_CascadeClassifier_GPU_visualizeInPlace_set(IntPtr obj, int value);
238+
239+
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
240+
public static extern CvSize gpu_CascadeClassifier_GPU_getClassifierSize(IntPtr obj);
241+
242+
#endregion
243+
205244
#region HogDescriptor
206245
[DllImport(DllExtern, CallingConvention = CallingConvention.Cdecl)]
207246
public static extern int HOGDescriptor_sizeof();
Lines changed: 208 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
using System;
2+
3+
namespace OpenCvSharp.CPlusPlus.Gpu
4+
{
5+
// ReSharper disable InconsistentNaming
6+
7+
/// <summary>
8+
/// The cascade classifier class for object detection:
9+
/// supports old haar and new lbp xlm formats and nvbin for haar cascades only.
10+
/// </summary>
11+
// ReSharper disable once InconsistentNaming
12+
public class CascadeClassifier_GPU : DisposableCvObject
13+
{
14+
/// <summary>
15+
/// Track whether Dispose has been called
16+
/// </summary>
17+
private bool disposed = false;
18+
19+
#region Init and Disposal
20+
/// <summary>
21+
/// Default constructor
22+
/// </summary>
23+
public CascadeClassifier_GPU()
24+
{
25+
Cv2Gpu.ThrowIfGpuNotAvailable();
26+
ptr = NativeMethods.gpu_CascadeClassifier_GPU_new1();
27+
if (ptr == IntPtr.Zero)
28+
throw new OpenCvSharpException();
29+
}
30+
31+
/// <summary>
32+
/// CascadeClassifier_GPU Constructor
33+
/// </summary>
34+
/// <param name="fileName"></param>
35+
public CascadeClassifier_GPU(string fileName)
36+
{
37+
Cv2Gpu.ThrowIfGpuNotAvailable();
38+
ptr = NativeMethods.gpu_CascadeClassifier_GPU_new2(fileName);
39+
if (ptr == IntPtr.Zero)
40+
throw new OpenCvSharpException();
41+
}
42+
43+
#if LANG_JP
44+
/// <summary>
45+
/// リソースの解放
46+
/// </summary>
47+
/// <param name="disposing">
48+
/// trueの場合は、このメソッドがユーザコードから直接が呼ばれたことを示す。マネージ・アンマネージ双方のリソースが解放される。
49+
/// falseの場合は、このメソッドはランタイムからファイナライザによって呼ばれ、もうほかのオブジェクトから参照されていないことを示す。アンマネージリソースのみ解放される。
50+
///</param>
51+
#else
52+
/// <summary>
53+
/// Clean up any resources being used.
54+
/// </summary>
55+
/// <param name="disposing">
56+
/// If disposing equals true, the method has been called directly or indirectly by a user's code. Managed and unmanaged resources can be disposed.
57+
/// 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.
58+
/// </param>
59+
#endif
60+
protected override void Dispose(bool disposing)
61+
{
62+
if (!disposed)
63+
{
64+
try
65+
{
66+
if (IsEnabledDispose)
67+
{
68+
NativeMethods.gpu_CascadeClassifier_GPU_delete(ptr);
69+
}
70+
disposed = true;
71+
}
72+
finally
73+
{
74+
base.Dispose(disposing);
75+
}
76+
}
77+
}
78+
79+
#endregion
80+
81+
#region Properties
82+
83+
/// <summary>
84+
///
85+
/// </summary>
86+
public bool FindLargestObject
87+
{
88+
get
89+
{
90+
if (disposed)
91+
throw new ObjectDisposedException(GetType().Name);
92+
return NativeMethods.gpu_CascadeClassifier_GPU_findLargestObject_get(ptr) != 0;
93+
}
94+
set
95+
{
96+
if (disposed)
97+
throw new ObjectDisposedException(GetType().Name);
98+
NativeMethods.gpu_CascadeClassifier_GPU_findLargestObject_set(ptr, value ? 0 : 1);
99+
}
100+
}
101+
102+
/// <summary>
103+
///
104+
/// </summary>
105+
public bool VisualizeInPlace
106+
{
107+
get
108+
{
109+
if (disposed)
110+
throw new ObjectDisposedException(GetType().Name);
111+
return NativeMethods.gpu_CascadeClassifier_GPU_visualizeInPlace_get(ptr) != 0;
112+
}
113+
set
114+
{
115+
if (disposed)
116+
throw new ObjectDisposedException(GetType().Name);
117+
NativeMethods.gpu_CascadeClassifier_GPU_visualizeInPlace_set(ptr, value ? 0 : 1);
118+
}
119+
}
120+
121+
#endregion
122+
123+
#region Methods
124+
125+
#if LANG_JP
126+
/// <summary>
127+
/// リソースの解放
128+
/// </summary>
129+
#else
130+
/// <summary>
131+
/// Clean up any resources being used.
132+
/// </summary>
133+
#endif
134+
public void Release()
135+
{
136+
if (disposed)
137+
throw new ObjectDisposedException(GetType().Name);
138+
NativeMethods.gpu_CascadeClassifier_GPU_release(ptr);
139+
}
140+
141+
/// <summary>
142+
///
143+
/// </summary>
144+
/// <param name="image"></param>
145+
/// <param name="objectsBuf"></param>
146+
/// <param name="scaleFactor"></param>
147+
/// <param name="minNeighbors"></param>
148+
/// <param name="minSize"></param>
149+
/// <returns>number of detected objects</returns>
150+
public int DetectMultiScale(
151+
GpuMat image, GpuMat objectsBuf,
152+
double scaleFactor = 1.2, int minNeighbors = 4, Size? minSize = null)
153+
{
154+
if (disposed)
155+
throw new ObjectDisposedException(GetType().Name);
156+
157+
CvSize minSizeVal = minSize.GetValueOrDefault(new Size());
158+
159+
int ret = NativeMethods.gpu_CascadeClassifier_GPU_detectMultiScale1(
160+
ptr, image.CvPtr, objectsBuf.CvPtr, scaleFactor, minNeighbors, minSizeVal);
161+
162+
GC.KeepAlive(image);
163+
GC.KeepAlive(objectsBuf);
164+
return ret;
165+
}
166+
167+
/// <summary>
168+
///
169+
/// </summary>
170+
/// <param name="image"></param>
171+
/// <param name="objectsBuf"></param>
172+
/// <param name="maxObjectSize"></param>
173+
/// <param name="minSize"></param>
174+
/// <param name="scaleFactor"></param>
175+
/// <param name="minNeighbors"></param>
176+
/// <returns>number of detected objects</returns>
177+
public int DetectMultiScale(
178+
GpuMat image, GpuMat objectsBuf,
179+
Size maxObjectSize, Size? minSize = null, double scaleFactor = 1.1, int minNeighbors = 4)
180+
{
181+
if (disposed)
182+
throw new ObjectDisposedException(GetType().Name);
183+
184+
CvSize minSizeVal = minSize.GetValueOrDefault(new Size());
185+
186+
int ret = NativeMethods.gpu_CascadeClassifier_GPU_detectMultiScale2(
187+
ptr, image.CvPtr, objectsBuf.CvPtr, maxObjectSize, minSizeVal,
188+
scaleFactor, minNeighbors);
189+
190+
GC.KeepAlive(image);
191+
GC.KeepAlive(objectsBuf);
192+
return ret;
193+
}
194+
195+
196+
/// <summary>
197+
///
198+
/// </summary>
199+
public Size GetClassifierSize()
200+
{
201+
if (disposed)
202+
throw new ObjectDisposedException(GetType().Name);
203+
return NativeMethods.gpu_CascadeClassifier_GPU_getClassifierSize(ptr);
204+
}
205+
206+
#endregion
207+
}
208+
}

src/OpenCvSharp.CPlusPlus/modules/gpu/StereoBM_GPU.cs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
namespace OpenCvSharp.CPlusPlus.Gpu
55
{
6+
// ReSharper disable InconsistentNaming
7+
68
#if LANG_JP
79
/// <summary>
810
///
@@ -12,15 +14,10 @@ namespace OpenCvSharp.CPlusPlus.Gpu
1214
///
1315
/// </summary>
1416
#endif
15-
// ReSharper disable once InconsistentNaming
1617
public class StereoBM_GPU : DisposableCvObject
1718
{
1819
#region Fields
1920
/// <summary>
20-
/// sizeof(StereoBM_GPU)
21-
/// </summary>
22-
public static readonly int SizeOf;
23-
/// <summary>
2421
/// Track whether Dispose has been called
2522
/// </summary>
2623
private bool disposed = false;

src/OpenCvSharp/Src/DisposableObject.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,8 @@ protected IntPtr AllocMemory(int size)
239239
#endif
240240
protected void NotifyMemoryPressure(long size)
241241
{
242+
// マルチスレッド動作時にロックがかかるらしい。いったん廃止
243+
/*
242244
if (!IsEnabledDispose)
243245
return;
244246
if (size == 0)
@@ -251,6 +253,7 @@ protected void NotifyMemoryPressure(long size)
251253
252254
AllocatedMemorySize = size;
253255
GC.AddMemoryPressure(size);
256+
*/
254257
}
255258

256259
#if LANG_JP

src/OpenCvSharpExtern/OpenCvSharpExtern.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@
234234
</ItemGroup>
235235
<ItemGroup>
236236
<ClInclude Include="calib3d.h" />
237+
<ClInclude Include="gpu_CascadeClassifier_GPU.h" />
237238
<ClInclude Include="core.h" />
238239
<ClInclude Include="core_AlgorithmInfo.h" />
239240
<ClInclude Include="core_InputArray.h" />

src/OpenCvSharpExtern/OpenCvSharpExtern.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,9 @@
225225
<ClInclude Include="imgproc_CLAHE.h">
226226
<Filter>Header Files\imgproc</Filter>
227227
</ClInclude>
228+
<ClInclude Include="gpu_CascadeClassifier_GPU.h">
229+
<Filter>Header Files\gpu</Filter>
230+
</ClInclude>
228231
</ItemGroup>
229232
<ItemGroup>
230233
<Filter Include="Source Files">

src/OpenCvSharpExtern/gpu.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
#include "gpu_CvMethods.h"
44
#include "gpu_HOGDescriptor.h"
55
#include "gpu_StereoBM_GPU.h"
6+
#include "gpu_CascadeClassifier_GPU.h"

0 commit comments

Comments
 (0)