Browse Source

git-svn-id: https://emgucv.svn.sourceforge.net/svnroot/emgucv/trunk@216 d7f09016-e345-0410-b530-edf29a71df78

UWP10
canming 17 years ago
parent
commit
4a7b0bc1e5
  1. 24
      Emgu.CV.Test/AutoTestVarious.cs
  2. 115
      Emgu.CV/BackgroundStatisticsModel.cs
  3. 24
      Emgu.CV/Contour.cs
  4. 6
      Emgu.CV/Emgu.CV.csproj
  5. 16
      Emgu.CV/PInvoke/CvInvoke.cs
  6. 58
      Emgu.CV/PInvoke/CvType/MCvBGStatModel.cs
  7. 25
      Emgu.CV/Seq.cs

24
Emgu.CV.Test/AutoTestVarious.cs

@ -318,5 +318,29 @@ namespace Emgu.CV.Test
Image<Bgr, Byte> tmp2 = tmp.MorphologyEx(element1, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_GRADIENT, 1);
Image<Bgr, Byte> tmp3 = tmp.MorphologyEx(element2, Emgu.CV.CvEnum.CV_MORPH_OP.CV_MOP_BLACKHAT, 1);
}
[Test]
public void TestBGModel()
{
int width = 300;
int height = 400;
Image<Bgr, Byte> bg = new Image<Bgr,byte>(width, height);
bg.SetRandNormal(new MCvScalar(), new MCvScalar(100, 100, 100));
Image<Bgr, Byte> img1 = bg.Copy();
img1.Draw(new Rectangle<double>(new Point2D<double>(width>>1, height >>1), width/10, height/10), new Bgr(Color.Red), -1);
Image<Bgr, Byte> img2 = bg.Copy();
img2.Draw(new Rectangle<double>(new Point2D<double>(width>>1 + 10 , height >>1), width/10, height/10), new Bgr(Color.Red), -1);
BackgroundStatisticsModel model1 = new BackgroundStatisticsModel(img1, Emgu.CV.CvEnum.BG_STAT_TYPE.GAUSSIAN_BG_MODEL);
model1.Update(img2);
BackgroundStatisticsModel model2 = new BackgroundStatisticsModel(img1, Emgu.CV.CvEnum.BG_STAT_TYPE.FGD_STAT_MODEL);
model2.Update(img2);
//Application.Run(new ImageViewer(model2.Foreground));
//Application.Run(new ImageViewer(model.BackGround));
}
}
}

115
Emgu.CV/BackgroundStatisticsModel.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
}
}

24
Emgu.CV/Contour.cs

@ -41,6 +41,12 @@ namespace Emgu.CV
MCvContour seq = MCvContour;
return seq.h_next == IntPtr.Zero ? null : new Contour(seq.h_next, Storage);
}
set
{
MCvContour seq = MCvContour;
seq.h_next = value == null ? IntPtr.Zero : value.Ptr;
Marshal.StructureToPtr(seq, _ptr, false);
}
}
/// <summary>
@ -53,6 +59,12 @@ namespace Emgu.CV
MCvContour seq = MCvContour;
return seq.h_prev == IntPtr.Zero ? null : new Contour(seq.h_prev, Storage);
}
set
{
MCvContour seq = MCvContour;
seq.h_prev = value == null ? IntPtr.Zero : value.Ptr;
Marshal.StructureToPtr(seq, _ptr, false);
}
}
/// <summary>
@ -65,6 +77,12 @@ namespace Emgu.CV
MCvContour seq = MCvContour;
return seq.v_next == IntPtr.Zero ? null : new Contour(seq.v_next, Storage);
}
set
{
MCvContour seq = MCvContour;
seq.v_next = value == null ? IntPtr.Zero : value.Ptr;
Marshal.StructureToPtr(seq, _ptr, false);
}
}
/// <summary>
@ -77,6 +95,12 @@ namespace Emgu.CV
MCvContour seq = MCvContour;
return seq.v_prev == IntPtr.Zero ? null : new Contour(seq.v_prev, Storage);
}
set
{
MCvContour seq = MCvContour;
seq.v_prev = value == null ? IntPtr.Zero : value.Ptr;
Marshal.StructureToPtr(seq, _ptr, false);
}
}
/// <summary>

6
Emgu.CV/Emgu.CV.csproj

@ -2,7 +2,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{9A1A77FE-F01B-495E-87B7-4B16E4F8C908}</ProjectGuid>
<OutputType>Library</OutputType>
@ -73,6 +73,7 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="BackgroundStatisticsModel.cs" />
<Compile Include="CameraCalibration\RotationVector3D.cs" />
<Compile Include="Color\Bgra.cs" />
<Compile Include="Contour.cs" />
@ -96,6 +97,7 @@
<Compile Include="IImage.cs" />
<Compile Include="Kalman.cs" />
<Compile Include="MotionHistory.cs" />
<Compile Include="PInvoke\CvType\MCvBGStatModel.cs" />
<Compile Include="PInvoke\CvType\MCvChain.cs" />
<Compile Include="PInvoke\CvType\MCvConnectedComp.cs" />
<Compile Include="PInvoke\CvType\MCvKalman.cs" />
@ -277,4 +279,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

16
Emgu.CV/PInvoke/CvInvoke.cs

@ -3593,6 +3593,7 @@ namespace Emgu.CV
public delegate int CvCallBack(int index, IntPtr buffer, ref MUserData user_data);
*/
#region Eigen Objects
#region cvEigenDecomposite function
/// <summary>
/// Calculates all decomposition coefficients for the input object using the previously calculated eigen objects basis and the averaged object
@ -3734,6 +3735,21 @@ namespace Emgu.CV
float[] coeffs,
IntPtr avg,
IntPtr proj);
#endregion
#region background statistic
/// <summary>
/// Create a Gaussian background model
/// </summary>
[DllImport(CVAUX_LIBRARY)]
public extern static IntPtr cvCreateGaussianBGModel(IntPtr img, IntPtr param);
/// <summary>
/// Create a background model
/// </summary>
[DllImport(CVAUX_LIBRARY)]
public extern static IntPtr cvCreateFGDStatModel(IntPtr image, IntPtr param);
#endregion
/// <summary>
/// Calculates disparity for stereo-pair

58
Emgu.CV/PInvoke/CvType/MCvBGStatModel.cs

@ -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;
}
}

25
Emgu.CV/Seq.cs

@ -173,6 +173,12 @@ namespace Emgu.CV
MCvSeq seq = MCvSeq;
return seq.h_next == IntPtr.Zero ? null : new Seq<T>(seq.h_next, Storage);
}
set
{
MCvSeq seq = MCvSeq;
seq.h_next = value == null ? IntPtr.Zero : value.Ptr;
Marshal.StructureToPtr(seq, _ptr, false);
}
}
/// <summary>
@ -185,6 +191,13 @@ namespace Emgu.CV
MCvSeq seq = MCvSeq;
return seq.h_prev == IntPtr.Zero ? null : new Seq<T>(seq.h_prev, Storage);
}
set
{
MCvSeq seq = MCvSeq;
seq.h_prev = value == null ? IntPtr.Zero : value.Ptr;
Marshal.StructureToPtr(seq, _ptr, false);
}
}
/// <summary>
@ -197,6 +210,12 @@ namespace Emgu.CV
MCvSeq seq = MCvSeq;
return seq.v_next == IntPtr.Zero ? null : new Seq<T>(seq.v_next, Storage);
}
set
{
MCvSeq seq = MCvSeq;
seq.v_next = value == null ? IntPtr.Zero : value.Ptr;
Marshal.StructureToPtr(seq, _ptr, false);
}
}
/// <summary>
@ -209,6 +228,12 @@ namespace Emgu.CV
MCvSeq seq = MCvSeq;
return seq.v_prev == IntPtr.Zero ? null : new Seq<T>(seq.v_prev, Storage);
}
set
{
MCvSeq seq = MCvSeq;
seq.v_prev = value == null ? IntPtr.Zero : value.Ptr;
Marshal.StructureToPtr(seq, _ptr, false);
}
}
/// <summary>

Loading…
Cancel
Save