1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
| using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using AForge.Video;
using AForge.Video.DirectShow;
using AForge.Vision.Motion;
using System.Drawing.Imaging;
using AForge.Imaging;
using AForge.Video.VFW;
namespace lecture_labial19mars2012.video
{
public partial class Aqusition : DevExpress.XtraEditors.XtraForm
{
private FilterInfoCollection videoCaptureDevices;
private VideoCaptureDevice Finalvideo;
AVIWriter writer;
int iCpt = 0;
MotionDetector detector = new MotionDetector(new SimpleBackgroundModelingDetector(), new MotionAreaHighlighting());
public Aqusition()
{
InitializeComponent();
}
private void Aqusition_Load(object sender, EventArgs e)
{
videoCaptureDevices=
new FilterInfoCollection(FilterCategory.VideoInputDevice);
foreach (FilterInfo videoCaptureDevice in videoCaptureDevices)
{
comboBox2.Items.Add(videoCaptureDevice.Name);
}
writer = new AVIWriter("wmv3");
writer.Open("videoe_enregistrer.avi", 640, 480);
timer1.Start();
comboBox2.SelectedIndex = 0; //make dafault to first cam
}
private void button1_Click(object sender, EventArgs e)
{
Finalvideo = new VideoCaptureDevice(videoCaptureDevices[comboBox2.SelectedIndex].MonikerString);
Finalvideo.DesiredFrameSize = new Size(160, 120);
Finalvideo.NewFrame += new NewFrameEventHandler(FinalVideo_NewFram);
Finalvideo.Start();
button1.Enabled = false;
button2.Enabled = true;
}
void FinalVideo_NewFram(object sender, NewFrameEventArgs eventArgs)
{
Bitmap image = (Bitmap)eventArgs.Frame.Clone();
Bitmap image2 = (Bitmap)eventArgs.Frame.Clone();
pictureBox1.Image = image;
writer.AddFrame(image);
if (detector.ProcessFrame(image2) > 0.5)
{
Test = true;
//timer1.Start();
//timer1.Enabled = true;
writer.AddFrame(image2);
}
if (Test == true)
{
writer.AddFrame(image2);
}
}
private void button2_Click(object sender, EventArgs e)
{
writer.Close();
timer1.Stop();
Test = true;
button1.Enabled = true;
button2.Enabled = false;
if (Finalvideo.IsRunning)
Finalvideo.Stop();
}
private void closed(object sender, FormClosedEventArgs e)
{
if (Finalvideo.IsRunning)
Finalvideo.Stop();
}
private void tick(object sender, EventArgs e)
{
if (iCpt < 3000)
iCpt += timer1.Interval;
else
timer1.Stop();
}
}
} |
Partager