分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow

也欢迎大家转载本篇文章。分享知识,造福人民,实现我们中华民族伟大复兴!

               

背景建模与前景检测(Background Generation And Foreground Detection)

 

http://www.cnblogs.com/xrwang/archive/2010/02/21/ForegroundDetection.html

作者:王先荣

前言
    在很多情况下,我们需要从一段视频或者一系列图片中找到感兴趣的目标,比如说当人进入已经打烊的超市时发出警报。为了达到这个目的,我们首先需要“学习”背景模型,然后将背景模型和当前图像进行比较,从而得到前景目标。

背景建模与前景检测 Background Generation And Foreground Detection

背景建模
    背景与前景都是相对的概念,以高速公路为例:有时我们对高速公路上来来往往的汽车感兴趣,这时汽车是前景,而路面以及周围的环境是背景;有时我们仅仅对闯入高速公路的行人感兴趣,这时闯入者是前景,而包括汽车之类的其他东西又成了背景。背景建模的方式很多,或高级或简单。不过各种背景模型都有自己适用的场合,即使是高级的背景模型也不能适用于任何场合。下面我将逐一介绍OpenCv中已经实现,或者在《学习OpenCv》这本书中介绍的背景建模方法。
1.帧差
    帧差可说是最简单的一种背景模型,指定视频中的一幅图像为背景,用当前帧与背景进行比较,根据需要过滤较小的差异,得到的结果就是前景了。OpenCv中为我们提供了一种动态计算阀值,然后用帧差进行前景检测的函数——cvChangeDetection(注:EmguCv中没有封装 cvChangeDetection,我将其声明到OpenCvInvoke类中,具体实现见文末代码)。而通过对两幅图像使用减法运算,然后再用指定阀值过滤的方法在《学习OpenCv》一书中有详细的介绍。它们的实现代码如下:

背景建模与前景检测 Background Generation And Foreground Detection帧差
背景建模与前景检测 Background Generation And Foreground Detection

            [DllImport("cvaux200.dll")]            public static extern void cvChangeDetection(IntPtr prev_frame, IntPtr curr_frame, IntPtr change_mask);            //backgroundMask为背景,imageBackgroundModel为背景模型,currentFrame为当前帧            if (backgroundMask == null)                backgroundMask = new Image<Gray, byte>(imageBackgroundModel.Size);            if (threshold == 0d)                //如果阀值为0,使用OpenCv中的自适应动态背景检测                OpenCvInvoke.cvChangeDetection(imageBackgroundModel.Ptr, currentFrame.Ptr, backgroundMask.Ptr);            else            {                //如果设置了阀值,使用帧差                Image<TColor, Byte> imageTemp = imageBackgroundModel.AbsDiff(currentFrame);                Image<Gray, Byte>[] images = imageTemp.Split();                backgroundMask.SetValue(0d);                foreach (Image<Gray, Byte> image in images)                    backgroundMask._Or(image.ThresholdBinary(new Gray(threshold), new Gray(255d)));            }            backgroundMask._Not();
背景建模与前景检测 Background Generation And Foreground Detection

对于类似无人值守的仓库防盗之类的场合,使用帧差效果估计很好。

2.背景统计模型
    背景统计模型是:对一段时间的背景进行统计,然后计算其统计数据(例如平均值、平均差分、标准差、均值漂移值等等),将统计数据作为背景的方法。 OpenCv中并未实现简单的背景统计模型,不过在《学习OpenCv》中对其中的平均背景统计模型有很详细的介绍。在模仿该算法的基础上,我实现了一系列的背景统计模型,包括:平均背景、均值漂移、标准差和标准协方差。对这些统计概念我其实不明白,在维基百科上看了好半天 -_-
调用背景统计模型很简单,只需4步而已:

背景建模与前景检测 Background Generation And Foreground Detection

//(1)初始化对象BackgroundStatModelBase<Bgr> bgModel = new BackgroundStatModelBase<Bgr>(BackgroundStatModelType.AccAvg);//(2)更新一段时间的背景图像,视情况反复调用(2)bgModel.Update(image);//(3)设置当前帧bgModel.CurrentFrame = currentFrame;//(4)得到背景或者前景Image<Gray,Byte> imageForeground = bgModel.ForegroundMask;
背景建模与前景检测 Background Generation And Foreground Detection

背景统计模型的实现代码如下:

背景建模与前景检测 Background Generation And Foreground Detection实现背景统计模型

 

3.编码本背景模型
    编码本的基本思路是这样的:针对每个像素在时间轴上的变动,建立多个(或者一个)包容近期所有变化的Box(变动范围);在检测时,用当前像素与Box去比较,如果当前像素落在任何Box的范围内,则为背景。
    在OpenCv中已经实现了编码本背景模型,不过实现方式与《学习OpenCv》中提到的方式略有不同,主要有:(1)使用单向链表来容纳Code Element;(2)清除消极的Code Element时,并未重置t。OpenCv中的以下函数与编码本背景模型相关:
cvCreateBGCodeBookModel  建立背景模型
cvBGCodeBookUpdate       更新背景模型
cvBGCodeBookClearStale   清除消极的Code Element
cvBGCodeBookDiff         计算得到背景与前景(注意:该函数仅仅设置背景像素为0,而对前景像素未处理,因此在调用前需要将所有的像素先置为前景)
cvReleaseBGCodeBookModel 释放资源
    在EmguCv中只实现了一部分编码本背景模型,在类BGCodeBookModel<TColor>中,可惜它把cvBGCodeBookDiff给搞忘记了 -_-
下面的代码演示了如果使用编码本背景模型:

背景建模与前景检测 Background Generation And Foreground Detection编码本模型
背景建模与前景检测 Background Generation And Foreground Detection

            //(1)初始化对象            if (rbCodeBook.Checked)            {                if (bgCodeBookModel != null)                {                    bgCodeBookModel.Dispose();                    bgCodeBookModel = null;                }                bgCodeBookModel = new BGCodeBookModel<Bgr>();            }            //(2)背景建模或者前景检测            bool stop = false;            while (!stop)            {                Image<Bgr, Byte> image = capture.QueryFrame().Clone();  //当前帧                bool isBgModeling, isFgDetecting;                       //是否正在建模,是否正在前景检测                lock (lockObject)                {                    stop = !isVideoCapturing;                    isBgModeling = isBackgroundModeling;                    isFgDetecting = isForegroundDetecting;                }                //得到设置的参数                SettingParam param = (SettingParam)this.Invoke(new GetSettingParamDelegate(GetSettingParam));                //code book                if (param.ForegroundDetectType == ForegroundDetectType.CodeBook)                {                    if (bgCodeBookModel != null)                    {                        //背景建模                        if (isBgModeling)                        {                            bgCodeBookModel.Update(image);                            //背景建模一段时间之后,清理陈旧的条目 (因为清理操作不会重置t,所以这里用求余数的办法来决定清理的时机)                            if (backgroundModelFrameCount % CodeBookClearPeriod == CodeBookClearPeriod - 1)                                bgCodeBookModel.ClearStale(CodeBookStaleThresh, Rectangle.Empty, null);                            backgroundModelFrameCount++;                            pbBackgroundModel.Image = bgCodeBookModel.BackgroundMask.Bitmap;                            //如果达到最大背景建模次数,停止背景建模                            if (param.MaxBackgroundModelFrameCount != 0 && backgroundModelFrameCount > param.MaxBackgroundModelFrameCount)                                this.Invoke(new NoParamAndReturnDelegate(StopBackgroundModel));                        }                        //前景检测                        if (isFgDetecting)                        {                            Image<Gray, Byte> imageFg = new Image<Gray, byte>(image.Size);                            imageFg.SetValue(255d);     //CodeBook在得出前景时,仅仅将背景像素置零,所以这里需要先将所有的像素都假设为前景                            CvInvoke.cvBGCodeBookDiff(bgCodeBookModel.Ptr, image.Ptr, imageFg.Ptr, Rectangle.Empty);                            pbBackgroundModel.Image = imageFg.Bitmap;                        }                    }                }                //更新视频图像                pbVideo.Image = image.Bitmap;            }            //(3)释放对象            if (bgCodeBookModel != null)            {                try                {                    bgCodeBookModel.Dispose();                }                catch { }            }
背景建模与前景检测 Background Generation And Foreground Detection

 

4.高级背景统计模型
    在OpenCv还实现了两种高级的背景统计模型,它们为别是:(1)FGD——复杂背景下的前景物体检测(Foreground object detection from videos containing complex background);(2)MOG——高斯混合模型(Mixture Of Gauss)。包括以下函数:
CvCreateFGDetectorBase  建立前景检测对象
CvFGDetectorProcess     更新前景检测对象
CvFGDetectorGetMask     获取前景
CvFGDetectorRelease     释放资源
    EmguCv将其封装到类FGDetector<TColor>中。我个人觉得OpenCv在实现这个模型的时候做得不太好,因为它将背景建模和前景检测糅合到一起了,无论你是否愿意,在建模的过程中也会检测前景,而只希望前景检测的时候,同时也会建模。我比较喜欢将背景建模和前景检测进行分离的设计。
调用的过程很简单,代码如下:

背景建模与前景检测 Background Generation And Foreground Detection高级背景统计模型

 

前景检测
    在建立好背景模型之后,通过对当前图像及背景的某种比较,我们可以得出前景。在上面的介绍中,已经包含了对前景的代码,在此不再重复。一般情况下,得到的前景包含了很多噪声,为了消除噪声,我们可以对前景图像进行开运算及闭运算,然后再丢弃比较小的轮廓。

本文的代码

背景建模与前景检测 Background Generation And Foreground Detection本文代码
背景建模与前景检测 Background Generation And Foreground Detection

using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Diagnostics;using System.Runtime.InteropServices;using System.Threading;using Emgu.CV;using Emgu.CV.CvEnum;using Emgu.CV.Structure;using Emgu.CV.UI;using Emgu.CV.VideoSurveillance;namespace ImageProcessLearn{    public partial class FormForegroundDetect : Form    {        //成员变量        Capture capture = null;                         //视频捕获对象        Thread captureThread = null;                    //视频捕获线程        private bool isVideoCapturing = true;           //是否正在捕获视频        private bool isBackgroundModeling = false;      //是否正在背景建模        private int backgroundModelFrameCount = 0;      //已经建模的视频帧数        private bool isForegroundDetecting = false;     //是否正在进行前景检测        private object lockObject = new object();       //用于锁定的对象        //各种前景检测方法对应的对象        BGCodeBookModel<Bgr> bgCodeBookModel = null;    //编码本前景检测        private const int CodeBookClearPeriod = 40;     //编码本的清理周期,更新这么多次背景之后,清理掉很少使用的陈旧条目        private const int CodeBookStaleThresh = 20;     //在清理编码本时,使用的阀值(stale大于该阀值的条目将被删除)        FGDetector<Bgr> fgDetector = null;              //Mog或者Fgd检测        BackgroundStatModelFrameDiff<Bgr> bgModelFrameDiff = null;      //帧差        BackgroundStatModelAccAvg<Bgr> bgModelAccAvg = null;            //平均背景        BackgroundStatModelRunningAvg<Bgr> bgModelRunningAvg = null;    //均值漂移        BackgroundStatModelSquareAcc<Bgr> bgModelSquareAcc = null;      //标准方差        BackgroundStatModelMultiplyAcc<Bgr> bgModelMultiplyAcc = null//标准协方差        public FormForegroundDetect()        {            InitializeComponent();        }        //窗体加载时        private void FormForegroundDetect_Load(object sender, EventArgs e)        {            //设置Tooltip            toolTip.Active = true;            toolTip.SetToolTip(rbMog, "高斯混合模型(Mixture Of Gauss)");            toolTip.SetToolTip(rbFgd, "复杂背景下的前景物体检测(Foreground object detection from videos containing complex background)");            toolTip.SetToolTip(txtMaxBackgroundModelFrameCount, "在背景建模时,使用的最大帧数,超出该值之后,将自动停止背景建模。\r\n对于帧差,总是只捕捉当前帧作为背景。\r\n如果设为零,背景检测将不会自动停止。");                        //打开摄像头视频捕获线程            capture = new Capture(0);            captureThread = new Thread(new ParameterizedThreadStart(CaptureWithEmguCv));            captureThread.Start(null);        }        //窗体关闭前        private void FormForegroundDetect_FormClosing(object sender, FormClosingEventArgs e)        {            //终止视频捕获            isVideoCapturing = false;            if (captureThread != null)                captureThread.Abort();            if (capture != null)                capture.Dispose();            //释放对象            if (bgCodeBookModel != null)            {                try                {                    bgCodeBookModel.Dispose();                }                catch { }            }            if (fgDetector != null)            {                try                {                    fgDetector.Dispose();                }                catch { }            }            if (bgModelFrameDiff != null)                bgModelFrameDiff.Dispose();            if (bgModelAccAvg != null)                bgModelAccAvg.Dispose();            if (bgModelRunningAvg != null)                bgModelRunningAvg.Dispose();            if (bgModelSquareAcc != null)                bgModelSquareAcc.Dispose();            if (bgModelMultiplyAcc != null)                bgModelMultiplyAcc.Dispose();        }        //EmguCv视频捕获        private void CaptureWithEmguCv(object objParam)        {            if (capture == null)                return;            bool stop = false;            while (!stop)            {                Image<Bgr, Byte> image = capture.QueryFrame().Clone();  //当前帧                bool isBgModeling, isFgDetecting;                       //是否正在建模,是否正在前景检测                lock (lockObject)                {                    stop = !isVideoCapturing;                    isBgModeling = isBackgroundModeling;                    isFgDetecting = isForegroundDetecting;                }                //得到设置的参数                SettingParam param = (SettingParam)this.Invoke(new GetSettingParamDelegate(GetSettingParam));                //code book                if (param.ForegroundDetectType == ForegroundDetectType.CodeBook)                {                    if (bgCodeBookModel != null && (isBgModeling || isFgDetecting))                    {                        //背景建模                        if (isBgModeling)                        {                            bgCodeBookModel.Update(image);                            //背景建模一段时间之后,清理陈旧的条目                            if (backgroundModelFrameCount % CodeBookClearPeriod == CodeBookClearPeriod - 1)                                bgCodeBookModel.ClearStale(CodeBookStaleThresh, Rectangle.Empty, null);                            backgroundModelFrameCount++;                            pbBackgroundModel.Image = bgCodeBookModel.BackgroundMask.Bitmap;                            //如果达到最大背景建模次数,停止背景建模                            if (param.MaxBackgroundModelFrameCount != 0 && backgroundModelFrameCount > param.MaxBackgroundModelFrameCount)                                this.Invoke(new NoParamAndReturnDelegate(StopBackgroundModel));                        }                        //前景检测                        if (isFgDetecting)                        {                            Image<Gray, Byte> imageFg = new Image<Gray, byte>(image.Size);                            imageFg.SetValue(255d);     //CodeBook在得出前景时,仅仅将背景像素置零,所以这里需要先将所有的像素都假设为前景                            CvInvoke.cvBGCodeBookDiff(bgCodeBookModel.Ptr, image.Ptr, imageFg.Ptr, Rectangle.Empty);                            pbBackgroundModel.Image = imageFg.Bitmap;                        }                    }                }                //fgd or mog                else if (param.ForegroundDetectType == ForegroundDetectType.Fgd || param.ForegroundDetectType == ForegroundDetectType.Mog)                {                    if (fgDetector != null && (isBgModeling || isFgDetecting))                    {                        //背景建模                        fgDetector.Update(image);                        backgroundModelFrameCount++;                        pbBackgroundModel.Image = fgDetector.BackgroundMask.Bitmap;                        //如果达到最大背景建模次数,停止背景建模                        if (param.MaxBackgroundModelFrameCount != 0 && backgroundModelFrameCount > param.MaxBackgroundModelFrameCount)                            this.Invoke(new NoParamAndReturnDelegate(StopBackgroundModel));                        //前景检测                        if (isFgDetecting)                        {                            pbBackgroundModel.Image = fgDetector.ForgroundMask.Bitmap;                        }                    }                }                //帧差                else if (param.ForegroundDetectType == ForegroundDetectType.FrameDiff)                {                    if (bgModelFrameDiff != null)                    {                        //背景建模                        if (isBgModeling)                        {                            bgModelFrameDiff.Update(image);                            backgroundModelFrameCount++;                            this.Invoke(new NoParamAndReturnDelegate(StopBackgroundModel)); //对于帧差,只需要捕获当前帧作为背景即可                        }                        //前景检测                        if (isFgDetecting)                        {                            bgModelFrameDiff.Threshold = param.Threshold;                            bgModelFrameDiff.CurrentFrame = image;                            pbBackgroundModel.Image = bgModelFrameDiff.ForegroundMask.Bitmap;                        }                    }                }                //平均背景                else if (param.ForegroundDetectType == ForegroundDetectType.AccAvg)                {                    if (bgModelAccAvg!=null)                    {                        //背景建模                        if (isBgModeling)                        {                            bgModelAccAvg.Update(image);                            backgroundModelFrameCount++;                            //如果达到最大背景建模次数,停止背景建模                            if (param.MaxBackgroundModelFrameCount != 0 && backgroundModelFrameCount > param.MaxBackgroundModelFrameCount)                                this.Invoke(new NoParamAndReturnDelegate(StopBackgroundModel));                        }                        //前景检测                        if (isFgDetecting)                        {                            bgModelAccAvg.CurrentFrame = image;                            pbBackgroundModel.Image = bgModelAccAvg.ForegroundMask.Bitmap;                        }                    }                }                //均值漂移                else if (param.ForegroundDetectType == ForegroundDetectType.RunningAvg)                {                    if (bgModelRunningAvg != null)                    {                        //背景建模                        if (isBgModeling)                        {                            bgModelRunningAvg.Update(image);                            backgroundModelFrameCount++;                            //如果达到最大背景建模次数,停止背景建模                            if (param.MaxBackgroundModelFrameCount != 0 && backgroundModelFrameCount > param.MaxBackgroundModelFrameCount)                                this.Invoke(new NoParamAndReturnDelegate(StopBackgroundModel));                        }                        //前景检测                        if (isFgDetecting)                        {                            bgModelRunningAvg.CurrentFrame = image;                            pbBackgroundModel.Image = bgModelRunningAvg.ForegroundMask.Bitmap;                        }                    }                }                //计算方差                else if (param.ForegroundDetectType == ForegroundDetectType.SquareAcc)                {                    if (bgModelSquareAcc != null)                    {                        //背景建模                        if (isBgModeling)                        {                            bgModelSquareAcc.Update(image);                            backgroundModelFrameCount++;                            //如果达到最大背景建模次数,停止背景建模                            if (param.MaxBackgroundModelFrameCount != 0 && backgroundModelFrameCount > param.MaxBackgroundModelFrameCount)                                this.Invoke(new NoParamAndReturnDelegate(StopBackgroundModel));                        }                        //前景检测                        if (isFgDetecting)                        {                            bgModelSquareAcc.CurrentFrame = image;                            pbBackgroundModel.Image = bgModelSquareAcc.ForegroundMask.Bitmap;                        }                    }                }                //协方差                else if (param.ForegroundDetectType == ForegroundDetectType.MultiplyAcc)                {                    if (bgModelMultiplyAcc != null)                    {                        //背景建模                        if (isBgModeling)                        {                            bgModelMultiplyAcc.Update(image);                            backgroundModelFrameCount++;                            //如果达到最大背景建模次数,停止背景建模                            if (param.MaxBackgroundModelFrameCount != 0 && backgroundModelFrameCount > param.MaxBackgroundModelFrameCount)                                this.Invoke(new NoParamAndReturnDelegate(StopBackgroundModel));                        }                        //前景检测                        if (isFgDetecting)                        {                            bgModelMultiplyAcc.CurrentFrame = image;                            pbBackgroundModel.Image = bgModelMultiplyAcc.ForegroundMask.Bitmap;                        }                    }                }                //更新视频图像                pbVideo.Image = image.Bitmap;            }        }        //用于在工作线程中更新结果的委托及方法        private delegate void AddResultDelegate(string result);        private void AddResultMethod(string result)        {            //txtResult.Text += result;        }        //用于在工作线程中获取设置参数的委托及方法        private delegate SettingParam GetSettingParamDelegate();        private SettingParam GetSettingParam()        {            ForegroundDetectType type = ForegroundDetectType.FrameDiff;            if (rbFrameDiff.Checked)                type = ForegroundDetectType.FrameDiff;            else if (rbAccAvg.Checked)                type = ForegroundDetectType.AccAvg;            else if (rbRunningAvg.Checked)                type = ForegroundDetectType.RunningAvg;            else if (rbMultiplyAcc.Checked)                type = ForegroundDetectType.MultiplyAcc;            else if (rbSquareAcc.Checked)                type = ForegroundDetectType.SquareAcc;            else if (rbCodeBook.Checked)                type = ForegroundDetectType.CodeBook;            else if (rbMog.Checked)                type = ForegroundDetectType.Mog;            else                type = ForegroundDetectType.Fgd;            int maxFrameCount = 0;            int.TryParse(txtMaxBackgroundModelFrameCount.Text, out maxFrameCount);            double threshold = 15d;            double.TryParse(txtThreshold.Text, out threshold);            if (threshold <= 0)                threshold = 15d;            return new SettingParam(type, maxFrameCount, threshold);        }        //没有参数及返回值的委托        private delegate void NoParamAndReturnDelegate();        //开始背景建模        private void btnStartBackgroundModel_Click(object sender, EventArgs e)        {            if (rbCodeBook.Checked)            {                if (bgCodeBookModel != null)                {                    bgCodeBookModel.Dispose();                    bgCodeBookModel = null;                }                bgCodeBookModel = new BGCodeBookModel<Bgr>();            }            else if (rbMog.Checked)            {                if (fgDetector != null)                {                    fgDetector.Dispose();                    fgDetector = null;                }                fgDetector = new FGDetector<Bgr>(FORGROUND_DETECTOR_TYPE.FGD);            }            else if (rbFgd.Checked)            {                if (fgDetector != null)                {                    fgDetector.Dispose();                    fgDetector = null;                }                fgDetector = new FGDetector<Bgr>(FORGROUND_DETECTOR_TYPE.MOG);            }            else if (rbFrameDiff.Checked)            {                if (bgModelFrameDiff != null)                {                    bgModelFrameDiff.Dispose();                    bgModelFrameDiff = null;                }                bgModelFrameDiff = new BackgroundStatModelFrameDiff<Bgr>();            }            else if (rbAccAvg.Checked)            {                if (bgModelAccAvg != null)                {                    bgModelAccAvg.Dispose();                    bgModelAccAvg = null;                }                bgModelAccAvg = new BackgroundStatModelAccAvg<Bgr>();            }            else if (rbRunningAvg.Checked)            {                if (bgModelRunningAvg != null)                {                    bgModelRunningAvg.Dispose();                    bgModelRunningAvg = null;                }                bgModelRunningAvg = new BackgroundStatModelRunningAvg<Bgr>();            }            else if (rbSquareAcc.Checked)            {                if (bgModelSquareAcc != null)                {                    bgModelSquareAcc.Dispose();                    bgModelSquareAcc = null;                }                bgModelSquareAcc = new BackgroundStatModelSquareAcc<Bgr>();            }            else if (rbMultiplyAcc.Checked)            {                if (bgModelMultiplyAcc != null)                {                    bgModelMultiplyAcc.Dispose();                    bgModelMultiplyAcc = null;                }                bgModelMultiplyAcc = new BackgroundStatModelMultiplyAcc<Bgr>();            }            backgroundModelFrameCount = 0;            isBackgroundModeling = true;            btnStartBackgroundModel.Enabled = false;            btnStopBackgroundModel.Enabled = true;            btnStartForegroundDetect.Enabled = false;            btnStopForegroundDetect.Enabled = false;        }        //停止背景建模        private void btnStopBackgroundModel_Click(object sender, EventArgs e)        {            StopBackgroundModel();        }        //停止背景建模        private void StopBackgroundModel()        {            lock (lockObject)            {                isBackgroundModeling = false;            }            btnStartBackgroundModel.Enabled = true;            btnStopBackgroundModel.Enabled = false;            btnStartForegroundDetect.Enabled = true;            btnStopForegroundDetect.Enabled = false;        }        //开始前景检测        private void btnStartForegroundDetect_Click(object sender, EventArgs e)        {            isForegroundDetecting = true;            btnStartBackgroundModel.Enabled = false;            btnStopBackgroundModel.Enabled = false;            btnStartForegroundDetect.Enabled = false;            btnStopForegroundDetect.Enabled = true;        }        //停止前景检测        private void btnStopForegroundDetect_Click(object sender, EventArgs e)        {            lock (lockObject)            {                isForegroundDetecting = false;            }            btnStartBackgroundModel.Enabled = true;            btnStopBackgroundModel.Enabled = false;            btnStartForegroundDetect.Enabled = true;            btnStopForegroundDetect.Enabled = false;        }    }    //前景检测方法枚举    public enum ForegroundDetectType    {        FrameDiff,        AccAvg,        RunningAvg,        MultiplyAcc,        SquareAcc,        CodeBook,        Mog,        Fgd    }    //设置参数    public struct SettingParam    {        public ForegroundDetectType ForegroundDetectType;        public int MaxBackgroundModelFrameCount;        public double Threshold;        public SettingParam(ForegroundDetectType foregroundDetectType, int maxBackgroundModelFrameCount, double threshold)        {            ForegroundDetectType = foregroundDetectType;            MaxBackgroundModelFrameCount = maxBackgroundModelFrameCount;            Threshold = threshold;        }    }}
背景建模与前景检测 Background Generation And Foreground Detection

    另外,细心的读者发现我忘记贴OpenCvInvoke类的实现代码了,这里补上。多谢指正。

背景建模与前景检测 Background Generation And Foreground DetectionOpenCvInvoke实现代码
背景建模与前景检测 Background Generation And Foreground Detection

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Drawing;using System.Runtime.InteropServices;using Emgu.CV.Structure;using Emgu.CV.CvEnum;namespace ImageProcessLearn{    /// <summary>   

新的改变

我们对Markdown编辑器进行了一些功能拓展与语法支持,除了标准的Markdown编辑器功能,我们增加了如下几点新功能,帮助你用它写博客:

  1. 全新的界面设计 ,将会带来全新的写作体验;
  2. 在创作中心设置你喜爱的代码高亮样式,Markdown 将代码片显示选择的高亮样式 进行展示;
  3. 增加了 图片拖拽 功能,你可以将本地的图片直接拖拽到编辑区域直接展示;
  4. 全新的 KaTeX数学公式 语法;
  5. 增加了支持甘特图的mermaid语法1 功能;
  6. 增加了 多屏幕编辑 Markdown文章功能;
  7. 增加了 焦点写作模式、预览模式、简洁写作模式、左右区域同步滚轮设置 等功能,功能按钮位于编辑区域与预览区域中间;
  8. 增加了 检查列表 功能。

功能快捷键

撤销:Ctrl/Command + Z
重做:Ctrl/Command + Y
加粗:Ctrl/Command + B
斜体:Ctrl/Command + I
标题:Ctrl/Command + Shift + H
无序列表:Ctrl/Command + Shift + U
有序列表:Ctrl/Command + Shift + O
检查列表:Ctrl/Command + Shift + C
插入代码:Ctrl/Command + Shift + K
插入链接:Ctrl/Command + Shift + L
插入图片:Ctrl/Command + Shift + G

合理的创建标题,有助于目录的生成

直接输入1次#,并按下space后,将生成1级标题。
输入2次#,并按下space后,将生成2级标题。
以此类推,我们支持6级标题。有助于使用TOC语法后生成一个完美的目录。

如何改变文本的样式

强调文本 强调文本

加粗文本 加粗文本

标记文本

删除文本

引用文本

H2O is是液体。

210 运算结果是 1024.

插入链接与图片

链接: link.

图片: 背景建模与前景检测 Background Generation And Foreground Detection

带尺寸的图片: 背景建模与前景检测 Background Generation And Foreground Detection

当然,我们为了让用户更加便捷,我们增加了图片拖拽功能。

如何插入一段漂亮的代码片

博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片.

// An highlighted block var foo = 'bar'; 

生成一个适合你的列表

  • 项目
    • 项目
      • 项目
  1. 项目1
  2. 项目2
  3. 项目3
  • 计划任务
  • 完成任务

创建一个表格

一个简单的表格是这么创建的:

项目 Value
电脑 $1600
手机 $12
导管 $1

设定内容居中、居左、居右

使用:---------:居中
使用:----------居左
使用----------:居右

第一列 第二列 第三列
第一列文本居中 第二列文本居右 第三列文本居左

SmartyPants

SmartyPants将ASCII标点字符转换为“智能”印刷标点HTML实体。例如:

TYPE ASCII HTML
Single backticks 'Isn't this fun?' ‘Isn’t this fun?’
Quotes "Isn't this fun?" “Isn’t this fun?”
Dashes -- is en-dash, --- is em-dash – is en-dash, — is em-dash

创建一个自定义列表

Markdown
Text-to-HTML conversion tool
Authors
John
Luke

如何创建一个注脚

一个具有注脚的文本。2

注释也是必不可少的

Markdown将文本转换为 HTML

KaTeX数学公式

您可以使用渲染LaTeX数学表达式 KaTeX:

Gamma公式展示 Γ(n)=(n1)!nN\Gamma(n) = (n-1)!\quad\forall n\in\mathbb N 是通过欧拉积分

Γ(z)=0tz1etdt&ThinSpace;. \Gamma(z) = \int_0^\infty t^{z-1}e^{-t}dt\,.

你可以找到更多关于的信息 LaTeX 数学表达式here.

新的甘特图功能,丰富你的文章

gantt
        dateFormat  YYYY-MM-DD
        title Adding GANTT diagram functionality to mermaid
        section 现有任务
        已完成               :done,    des1, 2014-01-06,2014-01-08
        进行中               :active,  des2, 2014-01-09, 3d
        计划一               :         des3, after des2, 5d
        计划二               :         des4, after des3, 5d
  • 关于 甘特图 语法,参考 这儿,

UML 图表

可以使用UML图表进行渲染。 Mermaid. 例如下面产生的一个序列图::

张三李四王五你好!李四, 最近怎么样?你最近怎么样,王五?我很好,谢谢!我很好,谢谢!李四想了很长时间,文字太长了不适合放在一行.打量着王五...很好... 王五, 你怎么样?张三李四王五

这将产生一个流程图。:

链接
长方形
圆角长方形
菱形
  • 关于 Mermaid 语法,参考 这儿,

FLowchart流程图

我们依旧会支持flowchart的流程图:

  • 关于 Flowchart流程图 语法,参考 这儿.

导出与导入

导出

如果你想尝试使用此编辑器, 你可以在此篇文章任意编辑。当你完成了一篇文章的写作, 在上方工具栏找到 文章导出 ,生成一个.md文件或者.html文件进行本地保存。

导入

如果你想加载一篇你写过的.md文件或者.html文件,在上方工具栏可以选择导入功能进行对应扩展名的文件导入,
继续你的创作。


  1. mermaid语法说明 ↩︎

  2. 注脚的解释 ↩︎

相关文章: