Example #1
0
 void _capturer_CaptureFinished(object sender, EventArgs e)
 {
     _capturer.SaveAsVideo();
     _capturer = null;
     _images.Clear();
     StatusBarItem1.Text = "Done";
 }
Example #2
0
        private bool CheckChanges(BitmapSource image, BitmapSource prevImage, List <HotSpot> hotSpots, int sensitivity)
        {
            System.Drawing.Bitmap innerImage     = CaptureObject.BitmapFromSource(image);
            System.Drawing.Bitmap innerPrevImage = CaptureObject.BitmapFromSource(prevImage);
            try
            {
                foreach (HotSpot hotSpot in hotSpots)
                {
                    float sum    = 0;
                    float result = 0;
                    float leftPixel;
                    float rightPixel;
                    int   left   = Convert.ToInt32(hotSpot.Bound.Left);
                    int   right  = Convert.ToInt32(hotSpot.Bound.Right);
                    int   top    = Convert.ToInt32(hotSpot.Bound.Top);
                    int   bottom = Convert.ToInt32(hotSpot.Bound.Bottom);
                    for (int i = left; i < right; i++)
                    {
                        for (int j = top; j < bottom; j++)
                        {
                            leftPixel  = RgbToGray(innerImage.GetPixel(i, j));
                            rightPixel = RgbToGray(innerPrevImage.GetPixel(i, j));
                            result    += Math.Abs(leftPixel - rightPixel);
                            sum       += 1;
                        }
                    }

                    result = result / sum;
                    DeltaList.Items.Add(result);
                    if (DeltaList.Items.Count > 10)
                    {
                        DeltaList.Items.RemoveAt(0);
                    }

                    if (result == 0)
                    {
                        zeroCount++;
                        if (zeroCount == 10)
                        {
                            zeroCount = 0;
                            RecycleDevice();
                        }
                    }

                    if (result > sensitivity)
                    {
                        return(true);
                    }
                }

                return(false);
            }
            finally
            {
                innerImage.Dispose();
                innerPrevImage.Dispose();
                GC.Collect();
            }
        }
Example #3
0
        private void CaptureVideo()
        {
            if (_capturer != null)
            {
                return;
            }

            _capturer = new CaptureObject(_dataPath);
            _capturer.Start(_maxBuffer * 2, _images, _fps);
            _capturer.CaptureFinished += _capturer_CaptureFinished;
            StatusBarItem1.Text        = "Capturing";
        }
Example #4
0
        private void RecycleDevice()
        {
            bool isEnabled = _dispatcherTimer.IsEnabled;

            _dispatcherTimer.Stop();
            _capturer = null;
            _images.Clear();
            MainPlayer.Device = null;
            while (_capDevice.IsRunning)
            {
                Thread.Sleep(100);
            }
            _capDevice        = new CapDevice(CapDevice.DeviceMonikers[0].MonikerString);
            MainPlayer.Device = _capDevice;

            if (isEnabled)
            {
                _dispatcherTimer.Start();
            }
        }