24
Санкт-Петербургский Государственный Политехнический Университет Факультет Управления и Информационных Технологий Кафедра Информационных Технологий в Проектировании Курсовая работа «Детектор движения из веб-камеры» По предмету «Системы реального времени» Студент группы 4241/10: Исаков Е.В. Преподователь: Вербова Н.М.

СРВ курсовая (1) (2)

Embed Size (px)

Citation preview

-

-

4241/10: .. : ..

1 , 2011.

1. ................................................................................................................................................ 2 2. ............................................................................................................................ 3 3. ............................................................................................ 4 4. ............................................................................................................. 5 4.1. .................................................................................................................. 5 4.2. USB web- ........................................................................................................ 5 4.3. ................................................................................................................. 5 4.4. ................................................................................................................... 7 5. ........................................................................................................ 9 5.1. .............................................................................................. 9 5.2. ................................................................................................ 9 6. ...................................................................................................11 6.1. USB web ...........................................................................................................................11 6.2. USB ................................................................................................................... 0 7. ........................................................................................................................................... 2 8. ............................................................................................................................... 3 1. .............................................................................................................. 4

2

1. . , , . , . ( ) . . . , , .

3

2. , , USB web-, - . . , , , .

4

3. : 1) USB Web- 2) 3) Web- . . , , , , . , web- . , . . 1) Web- . 2) usb-, web-; , . Windows .Net Framework 4.0. . 3) . , .

5

4. 4.1. : . , Windows. USB web- USB . , , . , - .

Web-

- ()

4.2.

USB web

web- : - - - - - - () 1. - USB web- - 3:4, . - . , , , . web- - ( ), , ( ) . web- , -.

4.3.

, . . , , .

6

. .

2.

PCI (Peripherial Component Interconnect bus) . ( , , SCSI-, ) . , , . AGP (Accelerated Graphic Port - ), , , PCI. . ( , CD-ROM, DVD-ROM) UDMA (Ultra Direct Memory Access - ).

7 USB (Universal Serial Bus),

3. USB AVR

.

4.4.

( 3.5 jack), . .

8

4.

, . . , . , . . , , .

5.

9

5. 5.1.

?

5.2.

, . , , . , , . ( ) .

10 , web-. . web- , . . , . , . , , AND. , . . , . OpenCV - Sub, . , AND. , . 0 255. . 255 , . . , , . , . , . . , , . .Net Framework Play, wav . , .

11

6. 6.1. USB web USB , , 3- . (. 6) USB USB, LPT .

6. USB web

X3 X1 . X5 - USB . X4 X2. , X8. X7 LPT , X6 USB . : / D1 VT1 VT2 VD1 C1, C2, C3, C4 5 R1-R15 X6, X7 CD4066BCM BC847 BC857 BZX84-C27 0.1 100 16v

SOIC SOT23 SOT23 SOT23 0805 SMD D 0805

6.2.

USB

USB USB . USB (. 7)

7. USB 5- -

1 USB . USB ID.

ID , USB ID ( UID), USB . ID , ID. , .

, (, ) , .. . , USB ( ID), "" ( HOST ), . . USB , (Full Speed Low Speed) UDP/UDM. LSM UDCON UDM ( Low Speed) UDP( Full Speed).

8. USB , UDP UDM, . UGND - "" , VBus - +5V . D+ , D- .

2

7. - web-. ( ), , . ( ) . , . , ( ) , , .

3

8. 1. Bradski, G., & Kaehler, A. (2008) Learning OpenCv, OReilly Media, p. 16-87 2. . (2008). . 1:54, 07 2011 http://www.5byte.ru/10/0022.php 3. . (2010). Claw.ru: . 1:54, 07 2011 http://tehno.claw.ru/shared/kinder/0330.htm 4. - Philips ToUcam Pro 740k. . 2:02, 07 2011 http://scope.narod.ru/anton/webcam.html 5. USB AVR ATmega32U6, AT90USB64, AT90USB128. . 2:04, 07 2011 http://www.gaw.ru/html.cgi/txt/doc/micros/avr/usb_contr/index.htm 6. web-. -.. 2:16, 07 2011 http://www.web-kamera.ru/device/

4

1. namespace CvMoveDetection { public partial class VideoViewer : Form { private bool _beep = false; private System.Media.SoundPlayer player; private SimpleProcessing sp; public VideoViewer() { InitializeComponent(); player = new System.Media.SoundPlayer(); player.SoundLocation = "notify.wav"; trackBar1.ValueChanged += new EventHandler(trackBar1_ValueChanged); USBWebCam.NewFrameEvent += USBWebCamOnNewFrameEvent; sp = new SimpleProcessing(); sp.Init(); sp.SimpleProcessedFrame += new SimpleProcessing.SimpleProcessedFrameHandler(sp_SimpleProcessedFrame); USBWebCam.AddFrameProcessing(sp); USBWebCam.Start(); } void trackBar1_ValueChanged(object sender, EventArgs e) { sp.Sense = trackBar1.Value; } void sp_SimpleProcessedFrame(object sender, FrameEvent e) { if (Utils.DetectMove(e.Frame) && !_beep) Play(); } private void Play() { if (!_beep) ThreadPool.QueueUserWorkItem(ignoredState => { _beep = true; player.PlaySync(); _beep = false; }); } private void USBWebCamOnNewFrameEvent(FrameEvent e) { pictureBox1.Image = (Bitmap)e.Frame.Clone(); } private void checkBox1_CheckedChanged(object sender, EventArgs e) { sp.Debug = checkBox1.Checked; } } public class USBWebCam {

5public delegate void FrameEventHandler(FrameEvent e); public static event FrameEventHandler NewFrameEvent; private const int FPS = 10; private static List _filters = new List(); private static CvCapture _camera; public static void Start() { _camera = CvCapture.FromCamera(0); //need to query frame every 1000/FPS ms Timer timer = new Timer(); timer.Interval = FPS; timer.Tick += delegate(object sender, EventArgs e) { using (IplImage frame = _camera.QueryFrame()) { PreProcessFrame(frame); ProcessFrame(frame); PostProcessFrame(frame); } }; timer.Start(); } public static void AddFrameProcessing(IFrameProcessing frameProcessing) { _filters.Add(frameProcessing); } private static void PreProcessFrame(IplImage frame) { if (NewFrameEvent != null) NewFrameEvent(new FrameEvent(frame.ToBitmap())); } private static void ProcessFrame(IplImage frame) { foreach (IFrameProcessing filter in _filters) { IplImage filtered = filter.ProcessFrame(frame); filter.RaiseFrameProcessingEvent(filtered); } } private static void PostProcessFrame(IplImage frame) { } } public interface IFrameProcessing { IplImage ProcessFrame(IplImage frame); void RaiseFrameProcessingEvent(IplImage processedFrame); }

public class SimpleProcessing : IFrameProcessing { public delegate void SimpleProcessedFrameHandler(object sender, FrameEvent e); public event SimpleProcessedFrameHandler SimpleProcessedFrame;

6private int _minT = 0; private int _maxT = 255; private bool _debug = false; public int Sense { get { return _minT; } set { _minT = value; } } public bool Debug { get { return _debug; } set { _debug = value; } } IplImage _prevFrame = null; public void Init() { } public OpenCvSharp.IplImage ProcessFrame(OpenCvSharp.IplImage frame) { if (_prevFrame == null) { _prevFrame = Cv.CreateImage(frame.GetSize(), frame.Depth, frame.NChannels); Cv.Copy(frame, _prevFrame); } //split current and previous frame in channels IplImage[] channels = frame.Split(); IplImage[] prevChannels = _prevFrame.Split(); //create sub results array IplImage[] sub = _prevFrame.Split(); for (int i = 0; i < frame.NChannels; i++) { //make image zero value sub[i].SetZero(); //make sub Cv.Sub(channels[i], prevChannels[i], sub[i]); } //create one channel simple image for save binary mask IplImage mask = Cv.CreateImage(frame.GetSize(), BitDepth.U8, 1); //initialization of mask if (frame.NChannels > 1) Cv.And(sub[0], sub[1], mask);

7else Cv.Copy(sub[0], mask); //mask store pixels what appears on every channels for (int i = 2; i < frame.NChannels; i++) Cv.And(sub[i], mask, mask); //simple make positive values for each pixel more than _minT and less than _maxT mask.Threshold(mask, _minT, _maxT, ThresholdType.Binary); if (_debug) Cv.ShowImage("Detection", mask); //save current frame for future Cv.Copy(frame, _prevFrame); return mask; } public void RaiseFrameProcessingEvent(OpenCvSharp.IplImage processedFrame) { SimpleProcessedFrameHandler handler = SimpleProcessedFrame; if (handler != null) handler(this, new FrameEvent(processedFrame.ToBitmap())); } } }