C#定義一個模板類

來源:互聯網
上載者:User

今天要實現模板類,尋找一些資料,發現非常有意思,估計對大家有協助,所以共用一下。

 

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.