Exemplo n.º 1
0
        private void Vfr_NewFrame(object sender, Sources.NewFrameEventArgs e)
        {
            vfr.NewFrame -= Vfr_NewFrame;
            if (e.Frame == null)
            {
                UISync.Execute(() => { MessageBox.Show(this, "Connection Failed"); });
            }
            else
            {
                UISync.Execute(() => { MessageBox.Show(this, "Connected!"); });
            }

            vfr.Close();
        }
Exemplo 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;

            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);
            }
        }
Exemplo n.º 3
0
        private void CameraNewFrame(object sender, NewFrameEventArgs e)
        {
            AreaControl.LastFrame = e.Frame;
            try
            {
                if (_filterForm != null)
                    _filterForm.ImageProcess = (Bitmap) e.Frame.Clone();

                if (_ctw != null && _ctw.TripWireEditor1 != null)
                {
                    _ctw.TripWireEditor1.LastFrame = e.Frame;
                }
                if (_pip != null && _pip.areaSelector1 != null)
                {
                    _pip.areaSelector1.LastFrame = e.Frame;
                }
            }
            catch(Exception ex)
            {
                MainForm.LogExceptionToFile(ex);
            }
        }
Exemplo n.º 4
0
        void NewCameraNewFrame(object sender, NewFrameEventArgs e)
        {
            if (CameraControl == null)
                return;

            CameraControl.NewFrame -= NewCameraNewFrame;

            string r = LocRm.CultureCode;
            if (r != "en")
                return;

            if (IsDisposed || !Visible)
                return;
            if (InvokeRequired)
            {
                BeginInvoke(new ShareDelegate(DoShareCamera));
                return;
            }
            DoShareCamera();
        }
Exemplo n.º 5
0
        private void CameraNewFrame(object sender, NewFrameEventArgs e)
        {
            try
            {
                if (_firstFrame)
                {
                    Camobject.resolution = e.Frame.Width + "x" + e.Frame.Height;
                    SetVideoSize();
                    _firstFrame = false;
                    var vlc = Camera.VideoSource as VlcStream;
                    if (vlc != null)
                        Seekable = vlc.Seekable;
                }

                if (VideoSourceErrorState)
                {
                    UpdateFloorplans(false);
                    var vl = VolumeControl;
                    if (vl?.AudioSource != null && vl.IsEnabled)
                    {
                        if (vl.AudioSource == Camera.VideoSource || vl.IsClone)
                        {
                            vl.AudioSource.LevelChanged -= vl.AudioDeviceLevelChanged;
                            vl.AudioSource.DataAvailable -= vl.AudioDeviceDataAvailable;
                            vl.AudioSource.AudioFinished -= vl.AudioDeviceAudioFinished;

                            vl.AudioSource.LevelChanged += vl.AudioDeviceLevelChanged;
                            vl.AudioSource.DataAvailable += vl.AudioDeviceDataAvailable;
                            vl.AudioSource.AudioFinished += vl.AudioDeviceAudioFinished;
                        }
                    }
                    VideoSourceErrorState = false;
                    _reconnectFailCount = 0;
                }

                lock (_lockobject)
                {
                    
                    var dt = Helper.Now.AddSeconds(0 - Camobject.recorder.bufferseconds);
                    if (!Recording)
                    {
                        while (Buffer.Count > 0)
                        {
                            Helper.FrameAction fa;
                            if (Buffer.TryPeek(out fa))
                            {
                                if (fa.TimeStamp < dt)
                                {
                                    if (Buffer.TryDequeue(out fa))
                                        fa.Nullify();
                                }
                                else
                                {
                                    break;
                                }
                            }
                        }
                    }
                    Buffer.Enqueue(new Helper.FrameAction(e.Frame, Camera.MotionLevel, Helper.Now));
                }
                

                if (_lastRedraw < Helper.Now.AddMilliseconds(0 - 1000 / MainForm.Conf.MaxRedrawRate))
                {
                    LastFrame = e.Frame;
                }

                if (_reconnectTime != DateTime.MinValue)
                {
                    _errorTime = _reconnectTime = DateTime.MinValue;
                    DoAlert("reconnect");
                }

                NewFrame?.Invoke(this, e);

                _errorTime = DateTime.MinValue;

            }
            catch (Exception ex)
            {
                ErrorHandler?.Invoke(ex.Message);
            }
        }
Exemplo n.º 6
0
        void NewCameraNewFrame(object sender, NewFrameEventArgs e)
        {
            if (CameraControl == null)
                return;

            CameraControl.NewFrame -= NewCameraNewFrame;

            if (MainForm.Conf.Language != "en")
                return;

            if (IsDisposed || !Visible)
                return;
            if (InvokeRequired)
            {
                BeginInvoke(new ShareDelegate(DoShareCamera));
                return;
            }
            DoShareCamera();
        }
Exemplo n.º 7
0
 public void CameraNewFrame(object sender, NewFrameEventArgs eventArgs)
 {
     LastFrame = (Bitmap)eventArgs.Frame.Clone();
 }