今天要实现模板类,查找一些资料,发现非常有意思,估计对大家有帮助,所以共享一下。
using System; using System.Collections.Generic; using System.Linq; using System.Text;
using Emgu.CV;
namespace VSL.Plugin.TrackingSystem.GaitAnalysisTrackingSystem {
/// <summary> /// 背景估计模型 /// </summary> /// <typeparam name="TColor"></typeparam> /// <typeparam name="TDepth"></typeparam> public class BackgroundEstimatorModel<TColor, TDepth> where TColor : Emgu.CV.IColor, new() { protected int _bufferMax;//缓冲区最大的尺寸 //背景缓冲区 protected Queue<Emgu.CV.Image<TColor, TDepth>> _buffer = new Queue<Emgu.CV.Image<TColor, TDepth>>(); protected Emgu.CV.Image<TColor, TDepth> _background = null;
public BackgroundEstimatorModel() {
}
/// <summary> /// 更新背景 /// </summary> /// <param name="image"></param> public virtual void Update(Emgu.CV.Image<TColor, TDepth> image) { if (_buffer.Count == _bufferMax)//达到缓冲队列的最大值,则出队列 { _buffer.Dequeue();//出队列 } _buffer.Enqueue(image);//新的帧入队列
//创建背景图像 if (_background == null) _background = new Emgu.CV.Image<TColor, TDepth>(image.Size);
foreach (var frame in _buffer) { //更具不同的算法更新背景
} } }
/// <summary> /// 灰度背景模型 /// </summary> public class GrayBackgroundEstimatorModel : BackgroundEstimatorModel<Gray, Byte> { //只支持灰度背景 public override void Update(Image<Gray, byte> image) { if (_buffer.Count == _bufferMax)//达到缓冲队列的最大值,则出队列 { _buffer.Dequeue();//出队列 } _buffer.Enqueue(image);//新的帧入队列
//创建背景图像 if (_background == null) _background = new Emgu.CV.Image<Gray, Byte>(image.Size);
foreach (var frame in _buffer) { //更具不同的算法更新背景
} }
} public enum BG_EISTIMATOR_TYPE { /// <summary> /// /// </summary> FGD_STAT_MODEL, /// <summary> /// Gaussian background model /// </summary> GAUSSIAN_BG_MODEL,
/// <summary> /// Move Forward /// </summary> MOVEFORWARD } }
|
请发表评论