Esempio n. 1
0
File: camera.cs Progetto: zzh56/iSpy
        protected virtual void Dispose(bool disposing)
        {
            if (_disposed)
            {
                return;
            }



            ClearMotionZones();
            Alarm           = null;
            NewFrame        = null;
            PlayingFinished = null;
            Plugin          = null;

            ForeBrush?.Dispose();
            BackBrush?.Dispose();
            DrawFont?.Dispose();
            _framerates?.Clear();

            Mask?.Dispose();
            Mask = null;

            VideoSource?.Dispose();
            VideoSource = null;


            try
            {
                MotionDetector?.Reset();
            }
            catch (Exception ex)
            {
                ErrorHandler?.Invoke(ex.Message);
            }
            MotionDetector = null;

            _disposed = true;
        }
Esempio n. 2
0
        private void VideoNewFrame(object sender, NewFrameEventArgs e)
        {
            var nf = NewFrame;
            var f  = e.Frame;

            if (_requestedToStop || nf == null || f == null)
            {
                return;
            }


            if (_lastframeEvent > DateTime.MinValue)
            {
                if ((Helper.Now < _nextFrameTarget))
                {
                    return;
                }
                CalculateFramerates();
            }

            _lastframeEvent = Helper.Now;

            if (_updateResources)
            {
                _updateResources = false;
                DrawFont.Dispose();
                DrawFont = null;
                ForeBrush.Dispose();
                ForeBrush = null;
                BackBrush.Dispose();
                BackBrush = null;
                SetMaskImage();
                RotateFlipType rft;
                if (Enum.TryParse(CW.Camobject.rotateMode, out rft))
                {
                    RotateFlipType = rft;
                }
                else
                {
                    RotateFlipType = RotateFlipType.RotateNoneFlipNone;
                }
            }


            Bitmap bmOrig  = null;
            bool   bMotion = false;

            lock (_sync)
            {
                try
                {
                    bmOrig = ResizeBmOrig(f);

                    if (RotateFlipType != RotateFlipType.RotateNoneFlipNone)
                    {
                        bmOrig.RotateFlip(RotateFlipType);
                    }

                    _width  = bmOrig.Width;
                    _height = bmOrig.Height;

                    if (ZPoint == Point.Empty)
                    {
                        ZPoint = new Point(bmOrig.Width / 2, bmOrig.Height / 2);
                    }

                    if (CW.NeedMotionZones)
                    {
                        CW.NeedMotionZones = !SetMotionZones(CW.Camobject.detector.motionzones);
                    }

                    if (Mask != null)
                    {
                        ApplyMask(bmOrig);
                    }

                    if (CW.Camobject.alerts.active && Plugin != null && Alarm != null)
                    {
                        bmOrig = RunPlugin(bmOrig);
                    }

                    var bmd = bmOrig.LockBits(new Rectangle(0, 0, bmOrig.Width, bmOrig.Height), ImageLockMode.ReadWrite, bmOrig.PixelFormat);

                    //this converts the image into a windows displayable image so do it regardless
                    using (var lfu = new UnmanagedImage(bmd))
                    {
                        if (_motionDetector != null)
                        {
                            bMotion = ApplyMotionDetector(lfu);
                        }
                        else
                        {
                            MotionDetected = false;
                        }

                        if (CW.Camobject.settings.FishEyeCorrect)
                        {
                            _feCorrect.Correct(lfu, CW.Camobject.settings.FishEyeFocalLengthPX,
                                               CW.Camobject.settings.FishEyeLimit, CW.Camobject.settings.FishEyeScale, ZPoint.X,
                                               ZPoint.Y);
                        }

                        if (ZFactor > 1)
                        {
                            var f1 = new ResizeNearestNeighbor(lfu.Width, lfu.Height);
                            var f2 = new Crop(ViewRectangle);
                            try
                            {
                                using (var imgTemp = f2.Apply(lfu))
                                {
                                    f1.Apply(imgTemp, lfu);
                                }
                            }
                            catch (Exception ex)
                            {
                                ErrorHandler?.Invoke(ex.Message);
                            }
                        }
                    }
                    bmOrig.UnlockBits(bmd);
                    PiP(bmOrig);
                    AddTimestamp(bmOrig);
                }
                catch (UnsupportedImageFormatException ex)
                {
                    CW.VideoSourceErrorState   = true;
                    CW.VideoSourceErrorMessage = ex.Message;

                    bmOrig?.Dispose();

                    return;
                }
                catch (Exception ex)
                {
                    bmOrig?.Dispose();

                    ErrorHandler?.Invoke(ex.Message);

                    return;
                }


                if (MotionDetector != null && !CW.Calibrating && MotionDetector.MotionProcessingAlgorithm is BlobCountingObjectsProcessing && !CW.PTZNavigate && CW.Camobject.settings.ptzautotrack)
                {
                    try
                    {
                        ProcessAutoTracking();
                    }
                    catch (Exception ex)
                    {
                        ErrorHandler?.Invoke(ex.Message);
                    }
                }
            }

            if (!_requestedToStop)
            {
                nf.Invoke(this, new NewFrameEventArgs(bmOrig));
            }
            if (bMotion)
            {
                TriggerDetect(this);
            }
        }
Esempio n. 3
0
        private void Overlay_Paint(object sender, PaintEventArgs e)
        {
            Graphics   g;
            Font       DrawFont  = new Font("Arial", 16);
            SolidBrush DrawBrush = new SolidBrush(Color.White);
            SolidBrush FillBrush = new SolidBrush(Color.Red);

            Image chatBox = Properties.Resources.ChatBox;

            g = e.Graphics;

            if (Draw)
            {
                g.DrawImage(chatBox, 10, 420);

                int loopCounterStr = 0;
                foreach (string s in StrToDraw)
                {
                    //Resets necessary variables before prefix check
                    string ToDraw = s;
                    DrawBrush.Color = Color.White;
                    DrawFont        = new Font("Arial", 16);

                    int DrawX = 30;
                    int DrawY = 440 + loopCounterStr * 52;

                    //prefix check, modifies string and font color depending on presence of prefix
                    if (s.Length >= 3)
                    {
                        if (s.Substring(0, 3).Equals("[y]"))
                        {
                            ToDraw = s.Replace("[y]", "(TEAM) ");

                            DrawBrush.Color = Color.Green;
                        }
                    }


                    if (ToDraw.Length >= 28)
                    {
                        string TempToDraw = ToDraw.Substring(0, 28);
                        ToDraw = ToDraw.Substring(28);

                        int LastSpacePos = TempToDraw.LastIndexOf(' ');
                        TempToDraw = TempToDraw.Remove(LastSpacePos, 1).Insert(LastSpacePos, "\n");

                        ToDraw = TempToDraw + ToDraw;

                        DrawFont = new Font("Arial", 12);
                    }

                    g.DrawString(ToDraw, DrawFont, DrawBrush, DrawX, DrawY);
                    loopCounterStr++;
                }
                loopCounterStr = 0;
                TimeDrawing();
            }



            DrawFont.Dispose();
            DrawBrush.Dispose();
            g.Dispose();
        }
Esempio n. 4
0
 internal void Draw(DrawFont drawCallback,
                    string text,
                    in Vector2 position,
Esempio n. 5
0
 internal void Draw(DrawFont drawCallback,
                    ReadOnlySpan <char> text,
                    in Vector2 position,