设置背景图像 [英] Set background image
本文介绍了设置背景图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好,
我是C#的新手。我知道编程,但我是C#的新手。我正在尝试AFORGE.net框架,我想制作一个动作探测器。探测器不会发出警报声,但会显示红色轮廓的运动区域。
这是我的FinalVideo_NewFrame方法代码。
Hello,
I am a newbie to C#. I know programming but I am new in C#. I was trying out the AFORGE.net framework and I wanna make a Motion Detector. The detector won't sound an alarm or so but would display the motion areas with red outline.
Here is my code for FinalVideo_NewFrame method.
using AForge.Imaging;
using AForge.Imaging.Filters;
using AForge.Video;
using AForge.Video.DirectShow;
using AForge.Vision;
using AForge.Vision.Motion;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace mtrack
{
public partial class Form1 : Form
{
private FilterInfoCollection VideoCaptureDevices;
private VideoCaptureDevice FinalVideo;
int height = 0, width = 0;
public Form1()
{
InitializeComponent();
{
VideoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo VideoCaptureDevice in VideoCaptureDevices)
{
comboBox1.Items.Add(VideoCaptureDevice.Name);
}
comboBox1.SelectedIndex = 0;
}
}
private void button1_Click(object sender, EventArgs e)
{
FinalVideo = new VideoCaptureDevice(VideoCaptureDevices[comboBox1.SelectedIndex].MonikerString);
FinalVideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFrame);
FinalVideo.Start();
}
private void button2_Click(object sender, EventArgs e)
{
FinalVideo.Stop();
}
void FinalVideo_NewFrame(object sender, NewFrameEventArgs e)
{
Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
Difference differenceFilter = new Difference();
IFilter thresholdFilter = new Threshold(15);
CustomFrameDifferenceDetector p = new CustomFrameDifferenceDetector();
MotionDetector detector = new MotionDetector(new CustomFrameDifferenceDetector(), new MotionBorderHighlighting());
try
{
Bitmap video = (Bitmap)e.Frame.Clone();
Bitmap currentFrame1 = video;
Bitmap backgroundframe=video;
backgroundframe=
backgroundframe = filter.Apply(backgroundframe);
differenceFilter.OverlayImage = backgroundframe;
Bitmap currentFrame;
if (currentFrame1!= null)
{
currentFrame = filter.Apply(currentFrame1);
// apply the filters
Bitmap tmp1 = differenceFilter.Apply(currentFrame);
Bitmap tmp2 = thresholdFilter.Apply(tmp1);
// create filter
IFilter erosionFilter = new Erosion();
// apply the filter
Bitmap tmp3 = erosionFilter.Apply(tmp2);
// extract red channel from the original image
IFilter extrachChannel = new ExtractChannel(RGB.R);
Bitmap redChannel = extrachChannel.Apply(video);
// merge red channel with motion regions
Merge mergeFilter = new Merge();
mergeFilter.OverlayImage = tmp3;
Bitmap tmp4 = mergeFilter.Apply(redChannel);
// replace red channel in the original image
ReplaceChannel replaceChannel = new ReplaceChannel(RGB.R, tmp4);
replaceChannel.ChannelImage = tmp4;
Bitmap tmp5 = replaceChannel.Apply(video);
pictureBox1.Image = backgroundframe;
pictureBox2.Image = currentFrame;
pictureBox3.Image = tmp5;
}
}
catch (Exception)
{
throw;
}
}
}
}
我的问题是在backgroundframe =中写什么?背景帧将充当参考框架。
先谢谢。
Avirup Basu
My question is what to write in "backgroundframe="? The backgroundframe will act as a reference frame.
Thanks in Advance.
Avirup Basu
推荐答案
有一吨这里有文章。只需要搜索它们:动作检测网站:codeproject.com [ ^ ]
There's a ton of articles here on it. Just need to search for them: motion detection site:codeproject.com[^]
这篇关于设置背景图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文