mirror of https://github.com/emgucv/emgucv.git
Browse Source
git-svn-id: https://emgucv.svn.sourceforge.net/svnroot/emgucv/trunk@216 d7f09016-e345-0410-b530-edf29a71df78
UWP10
git-svn-id: https://emgucv.svn.sourceforge.net/svnroot/emgucv/trunk@216 d7f09016-e345-0410-b530-edf29a71df78
UWP10

7 changed files with 266 additions and 2 deletions
-
24Emgu.CV.Test/AutoTestVarious.cs
-
115Emgu.CV/BackgroundStatisticsModel.cs
-
24Emgu.CV/Contour.cs
-
6Emgu.CV/Emgu.CV.csproj
-
16Emgu.CV/PInvoke/CvInvoke.cs
-
58Emgu.CV/PInvoke/CvType/MCvBGStatModel.cs
-
25Emgu.CV/Seq.cs
@ -0,0 +1,115 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
using Emgu.Util; |
|||
using System.Runtime.InteropServices; |
|||
|
|||
namespace Emgu.CV |
|||
{ |
|||
/// <summary>
|
|||
/// Create a background statistics model
|
|||
/// </summary>
|
|||
[Obsolete("Beta version, API might change in the future")] |
|||
public class BackgroundStatisticsModel : UnmanagedObject |
|||
{ |
|||
/// <summary>
|
|||
/// Create a BGStatModel
|
|||
/// </summary>
|
|||
/// <param name="img"></param>
|
|||
/// <param name="type"></param>
|
|||
public BackgroundStatisticsModel(Image<Bgr, Byte> img, Emgu.CV.CvEnum.BG_STAT_TYPE type) |
|||
{ |
|||
if (type == Emgu.CV.CvEnum.BG_STAT_TYPE.FGD_STAT_MODEL) |
|||
{ |
|||
_ptr = CvInvoke.cvCreateFGDStatModel(img, IntPtr.Zero); |
|||
} |
|||
else |
|||
{ |
|||
_ptr = CvInvoke.cvCreateGaussianBGModel(img, IntPtr.Zero); |
|||
} |
|||
} |
|||
|
|||
private delegate int UpdateFunction(IntPtr img, IntPtr statModel); |
|||
|
|||
/// <summary>
|
|||
/// Update the statistic model
|
|||
/// </summary>
|
|||
/// <param name="img"></param>
|
|||
public void Update(Image<Bgr, Byte> img) |
|||
{ |
|||
MCvBGStatModel model = MCvBGStatModel; |
|||
UpdateFunction updateFunction = (UpdateFunction)Marshal.GetDelegateForFunctionPointer(model.CvUpdateBGStatModel, typeof(UpdateFunction)); |
|||
updateFunction(img.Ptr, _ptr); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Get the CvBGStatModel structure
|
|||
/// </summary>
|
|||
public MCvBGStatModel MCvBGStatModel |
|||
{ |
|||
get |
|||
{ |
|||
return (MCvBGStatModel)Marshal.PtrToStructure(_ptr, typeof(MCvBGStatModel)); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Obtain the current background
|
|||
/// </summary>
|
|||
public Image<Bgr, Byte> BackGround |
|||
{ |
|||
get |
|||
{ |
|||
MCvBGStatModel statModel = MCvBGStatModel; |
|||
MIplImage iplImg = (MIplImage)Marshal.PtrToStructure(statModel.background, typeof(MIplImage)); |
|||
Image<Bgr, Byte> res = new Image<Bgr, byte>(iplImg.width, iplImg.height); |
|||
CvInvoke.cvCopy(statModel.background, res.Ptr, IntPtr.Zero); |
|||
return res; |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Obtain a mask for the current forground
|
|||
/// </summary>
|
|||
public Image<Gray, Byte> Foreground |
|||
{ |
|||
get |
|||
{ |
|||
MCvBGStatModel statModel = MCvBGStatModel; |
|||
MIplImage iplImg = (MIplImage)Marshal.PtrToStructure(statModel.foreground, typeof(MIplImage)); |
|||
Image<Gray, Byte> res = new Image<Gray, byte>(iplImg.width, iplImg.height); |
|||
CvInvoke.cvCopy(statModel.foreground, res.Ptr, IntPtr.Zero); |
|||
return res; |
|||
} |
|||
} |
|||
|
|||
private delegate void ReleaseFunction(ref IntPtr ptr); |
|||
|
|||
/// <summary>
|
|||
/// Release the BGStatModel and all the unmanaged memory associate with it
|
|||
/// </summary>
|
|||
protected override void DisposeObject() |
|||
{ |
|||
ReleaseFunction releaseFunction = (ReleaseFunction)Marshal.GetDelegateForFunctionPointer(MCvBGStatModel.CvReleaseBGStatModel, typeof(ReleaseFunction)); |
|||
releaseFunction(ref _ptr); |
|||
} |
|||
} |
|||
} |
|||
|
|||
namespace Emgu.CV.CvEnum |
|||
{ |
|||
/// <summary>
|
|||
/// The type of BGStatModel
|
|||
/// </summary>
|
|||
public enum BG_STAT_TYPE |
|||
{ |
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
FGD_STAT_MODEL, |
|||
/// <summary>
|
|||
/// Gaussian background model
|
|||
/// </summary>
|
|||
GAUSSIAN_BG_MODEL |
|||
} |
|||
} |
@ -0,0 +1,58 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace Emgu.CV |
|||
{ |
|||
/// <summary>
|
|||
/// Wrapper to the CvBGStatModel
|
|||
/// </summary>
|
|||
public struct MCvBGStatModel |
|||
{ |
|||
/// <summary>
|
|||
/// type of BG model
|
|||
/// </summary>
|
|||
public int type; |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public IntPtr CvReleaseBGStatModel; |
|||
|
|||
/// <summary>
|
|||
///
|
|||
/// </summary>
|
|||
public IntPtr CvUpdateBGStatModel; |
|||
|
|||
/// <summary>
|
|||
/// 8UC3 reference background image
|
|||
/// </summary>
|
|||
public IntPtr background; |
|||
|
|||
/// <summary>
|
|||
/// 8UC1 foreground image
|
|||
/// </summary>
|
|||
public IntPtr foreground; |
|||
|
|||
/// <summary>
|
|||
/// 8UC3 reference background image, can be null
|
|||
/// </summary>
|
|||
public IntPtr layers; |
|||
|
|||
/// <summary>
|
|||
/// can be zero
|
|||
/// </summary>
|
|||
public int layer_count; |
|||
|
|||
/// <summary>
|
|||
/// storage for “foreground_regions”
|
|||
/// </summary>
|
|||
public IntPtr storage; |
|||
|
|||
/// <summary>
|
|||
/// foreground object contours
|
|||
/// </summary>
|
|||
public IntPtr foreground_regions; |
|||
|
|||
} |
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue