基本信息
源码名称:AForge计算机视觉(通过摄像头检测运动)示例源码
源码大小:0.73M
文件格式:.rar
开发语言:C#
更新时间:2018-01-10
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 5 元×
微信扫码支付:5 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
通过摄像头检测运动,监测运动的物体
通过摄像头检测运动,监测运动的物体
使用AForge.Video; 使用AForge.Video.DirectShow; 使用AForge.Vision.Motion; 使用系统; 使用System.Collections.Generic; 使用System.ComponentModel; 使用System.Data; 使用System.Drawing; 使用System.Linq; 使用System.Text; 使用System.Threading; 使用System.Threading.Tasks; 使用System.Windows.Forms; 命名空间Vidoevision { 公共部分类Form1:Form { 私人只读MotionDetector _detector =新的MotionDetector(新的TwoFramesDifferenceDetector(),新的MotionAreaHighlighting()); private int _statIndex; private int _statReady; private readonly int [] _statCount = new int [15]; int _flga; public Form1() { InitializeComponent(); CheckForIllegalCrossThreadCalls = false; } public Form1(int flga) { InitializeComponent(); _flga = flga; } private void OpenVideoSource(IVideoSource source) { Cursor = Cursors.WaitCursor; CloseVideoSource(); videoSourcePlayer.VideoSource = new AsyncVideoSource(source); videoSourcePlayer.Start(); _statReady = 0; _statIndex = 0; timer.Start(); Cursor = Cursors.Default; } private void btnStart_Click(object sender, EventArgs e) { FrmCaptureDevice videoCaptureDeviceForm = new FrmCaptureDevice(); if (videoCaptureDeviceForm.ShowDialog() == DialogResult.OK) { OpenVideoSource(new VideoCaptureDevice(videoCaptureDeviceForm.SelectedDevice)); btnStart.Text = "停止"; } else { btnStart.Text = "开始"; CloseVideoSource(); } } private void CloseVideoSource() { Cursor = Cursors.WaitCursor; videoSourcePlayer.SignalToStop(); for (int i = 0; i < 50 && videoSourcePlayer.IsRunning; i ) { Thread.Sleep(100); } if (videoSourcePlayer.IsRunning) { videoSourcePlayer.Stop(); } timer.Stop(); if (_detector != null) { _detector.Reset(); } videoSourcePlayer.BorderColor = Color.Black; Cursor = Cursors.Default; } private void VideoSourcePlayerNewFrame(object sender, ref Bitmap image) { if (_detector == null) return; var motionValue = _detector.ProcessFrame(image); if (motionValue > 0) { lblMotionAlert.ForeColor = Color.Red; lblMotionAlert.Text = "检测到动作"; } else { lblMotionAlert.ForeColor = Color.Green; lblMotionAlert.Text = "未检测到移动"; } } private void Form1_FormClosing(object sender, FormClosingEventArgs e) { CloseVideoSource(); } private void timer_Tick(object sender, EventArgs e) { IVideoSource theVideoSource = videoSourcePlayer.VideoSource; if (theVideoSource == null) return; _statCount [_statIndex] = theVideoSource.FramesReceived; _statIndex = _statIndex 1; 如果(_statIndex> = 15) { _statIndex = 0; } 如果(_statReady <15) { _statReady = _statReady 1; } float single = 0f; for(int i = 0; i <_statReady; i) { single = single _statCount [i]; } single = single / _statReady; _statCount [_statIndex] = 0; lblFps.Text = string.Concat(single.ToString(“F2”),“fps”); } 私人无效Form1_Load(对象发件人,EventArgs e) { } } }