Пример #1
0
        private void SendGpsData(ref double gpsAltitiude)
        {
            gpsAltitiude += 0.01;

            var metadata = new MetadataStream
            {
                NavigationalData = new NavigationalData
                {
                    Altitude  = gpsAltitiude,
                    Latitude  = _random.Next(-90, 90),
                    Longitude = _random.Next(-180, 180)
                }
            };

            var result = _gpsProviderChannel.QueueMetadata(metadata, DateTime.UtcNow);

            if (result == false)
            {
                Trace.WriteLine(string.Format("{0}: Failed to write to GPS channel", DateTime.UtcNow));
            }
            else
            {
                BeginInvoke(new MethodInvoker(() =>
                {
                    if (sourceComboBox.SelectedIndex == 1)
                    {
                        DisplayMetadata(metadata);
                    }
                }));
            }
        }
Пример #2
0
        private void SendBoundingBoxData(Rectangle boundingBox, Vector dummyCenterOfGravity)
        {
            const int objectId = 1;

            var metadata = new MetadataStream
            {
                VideoAnalyticsItems =
                {
                    new VideoAnalytics
                    {
                        Frames =
                        {
                            new Frame(DateTime.UtcNow)
                            {
                                Objects =
                                {
                                    new OnvifObject(objectId)
                                    {
                                        Appearance = new Appearance
                                        {
                                            Shape = new Shape
                                            {
                                                BoundingBox     = boundingBox,
                                                CenterOfGravity = dummyCenterOfGravity
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            };

            var result = _boundingBoxProviderChannel.QueueMetadata(metadata, DateTime.UtcNow);

            if (result == false)
            {
                Trace.WriteLine(string.Format("{0}: Failed to write to bounding box channel", DateTime.UtcNow));
            }
            else
            {
                MoveBoundingBox(boundingBox);
                BeginInvoke(new MethodInvoker(() =>
                {
                    if (sourceComboBox.SelectedIndex == 0)
                    {
                        DisplayMetadata(metadata);
                    }
                }));
            }
        }
Пример #3
0
        /// <summary>
        /// For this sample, we provide JPEG frames.
        /// </summary>
        /// <param name="session"></param>
        /// <returns></returns>
        MediaData MediaProviderGetMediaData(MediaProviderSession session)
        {
            if (InvokeRequired)
            {
                // Get on the UI thread before executing the below code
                return(Invoke(new MediaProviderChannel.GetMediaDataDelegate(MediaProviderGetMediaData), session) as MediaData);
            }

            var random = new Random(DateTime.UtcNow.Millisecond);

            var metadata = new MetadataStream
            {
                NavigationalData = new NavigationalData
                {
                    Altitude  = _altitude,
                    Latitude  = random.Next(-90, 90),
                    Longitude = random.Next(-180, 180)
                }
            };

            _altitude += 0.01;

            _metadataProviderChannel.QueueMetadata(metadata, DateTime.UtcNow);

            var bitmap = new Bitmap(panelTimeDisplay.Width, panelTimeDisplay.Height);

            panelTimeDisplay.DrawToBitmap(bitmap, new Rectangle(new Point(0, 0), panelTimeDisplay.Size));
            var mediaData = new MediaData();

            using (var ms = new MemoryStream())
            {
                var qualityParam = new EncoderParameter(Encoder.Quality, session.Quality);
                bitmap.Save(ms, GetJpegEncoder(), new EncoderParameters(1)
                {
                    Param = new[] { qualityParam }
                });
                ms.Seek(0, SeekOrigin.Begin);
                mediaData.Bytes = new byte[ms.Length];
                ms.Read(mediaData.Bytes, 0, (int)ms.Length);
            }
            mediaData.DateTime = DateTime.UtcNow;
            return(mediaData);
        }
Пример #4
0
        private void buttonSendData_Click(object sender, EventArgs e)
        {
            var random = new Random(DateTime.UtcNow.Millisecond);

            var metadata = new MetadataStream
            {
                NavigationalData = new NavigationalData
                {
                    Altitude = random.NextDouble(),
                    Latitude = random.Next(-90, 90),
                    Longitude = random.Next(-180, 180)
                }
            };

            var result = _metadataProviderChannel.QueueMetadata(metadata, DateTime.UtcNow);
            if (result == false)
                Trace.WriteLine(string.Format("{0}: Failed to write to channel", DateTime.UtcNow));

            textMetadata.Text = _metadataSerializer.WriteMetadataXml(metadata);
            textBoxTime.Text = DateTime.Now.ToString("HH.mm.ss:fff");
        }
Пример #5
0
        private void SendNonStandardData()
        {
            var peopleCount = _random.Next(0, 100);

            var metadata = string.Format(_peopleCountXml, Guid.NewGuid(), peopleCount);

            var result = _nonStandardProviderChannel.QueueMetadata(metadata, DateTime.UtcNow);

            if (result == false)
            {
                Trace.WriteLine(string.Format("{0}: Failed to write to non-standard channel", DateTime.UtcNow));
            }
            else
            {
                BeginInvoke(new MethodInvoker(() =>
                {
                    if (sourceComboBox.SelectedIndex == 2)
                    {
                        DisplayMetadata(metadata);
                    }
                }));
            }
        }
Пример #6
0
        internal string SendMetadataBox(Blob[] blobs, int w, int h)
        {
            try
            {
                OnvifObject blob1 = new OnvifObject();
                OnvifObject blob2 = new OnvifObject();
                OnvifObject blob3 = new OnvifObject();
                OnvifObject blob4 = new OnvifObject();

                if (blobs.Length > 1)
                {
                    blob1 = CreateOnvifObject(blobs[0].CenterOfGravity.X, blobs[0].CenterOfGravity.Y, blobs[0].Area, blobs[0].ID.ToString(), 1, w, h);
                }
                if (blobs.Length > 2)
                {
                    blob2 = CreateOnvifObject(blobs[1].CenterOfGravity.X, blobs[1].CenterOfGravity.Y, blobs[1].Area, blobs[1].ID.ToString(), 2, w, h);
                }
                if (blobs.Length > 3)
                {
                    blob3 = CreateOnvifObject(blobs[2].CenterOfGravity.X, blobs[2].CenterOfGravity.Y, blobs[2].Area, blobs[2].ID.ToString(), 3, w, h);
                }
                if (blobs.Length > 4)
                {
                    blob4 = CreateOnvifObject(blobs[3].CenterOfGravity.X, blobs[3].CenterOfGravity.Y, blobs[3].Area, blobs[3].ID.ToString(), 4, w, h);
                }

                MetadataStream metadata = new MetadataStream
                {
                    VideoAnalyticsItems =
                    {
                        new VideoAnalytics
                        {
                            Frames =
                            {
                                new Frame(DateTime.UtcNow)
                                {
                                    Objects =
                                    {
                                        blob1, blob2, blob3, blob4
                                    }
                                }
                            }
                        }
                    }
                };

                var result = _metadataProviderChannel.QueueMetadata(metadata, DateTime.UtcNow);
                if (result == false)
                {
                    return(string.Format("{0}: Failed to write to channel", DateTime.UtcNow));
                }
                else
                {
                    return(_metadataSerializer.WriteMetadataXml(metadata));
                }
            }
            catch (Exception e)
            {
                return(e.Message);
            }
        }
Пример #7
0
        void SendData(object obj)
        {
            var token = (CancellationToken)obj;
            var dummyCenterOfGravity = new Vector {
                X = 0f, Y = 0f
            };
            var boundingBox = new Rectangle
            {
                Bottom    = BottomLimit,
                Left      = LeftLimit,
                Top       = BottomLimit + BoundingBoxSize,
                Right     = LeftLimit + BoundingBoxSize,
                LineColor = Colors[0],
                FillColor = Colors[Colors.Count / 2],
                LineDisplayPixelThickness = 1
            };

            var description = new DisplayText
            {
                Value      = Texts[0],
                FontFamily = FontFamilys[0],
                IsBold     = false,
                IsItalic   = false,
                Color      = Colors[0],
                Size       = MinTextSize,
                CenterX    = 0,
                CenterY    = 0
            };

            const int staticObjectId = 2;
            var       staticObject   = new OnvifObject(staticObjectId)
            {
                Appearance = new Appearance
                {
                    Shape = new Shape
                    {
                        BoundingBox = new Rectangle
                        {
                            Bottom = -BoundingBoxSize / 2,
                            Left   = -BoundingBoxSize / 2,
                            Top    = BoundingBoxSize / 2,
                            Right  = BoundingBoxSize / 2
                        }
                    },
                    Description = new DisplayText
                    {
                        Value = "This is just text"
                    }
                }
            };

            _currentDirection = MovementDirected.Up;

            while (token.IsCancellationRequested == false)
            {
                const int objectId = 1;

                var metadata = new MetadataStream
                {
                    VideoAnalyticsItems =
                    {
                        new VideoAnalytics
                        {
                            Frames =
                            {
                                new Frame(DateTime.UtcNow)
                                {
                                    Objects =
                                    {
                                        new OnvifObject(objectId)
                                        {
                                            Appearance = new Appearance
                                            {
                                                Shape = new Shape
                                                {
                                                    BoundingBox     = boundingBox,
                                                    CenterOfGravity = dummyCenterOfGravity
                                                },
                                                Description = description
                                            }
                                        },
                                        staticObject
                                    }
                                }
                            }
                        }
                    }
                };

                var result = _metadataProviderChannel.QueueMetadata(metadata, DateTime.UtcNow);
                if (result == false)
                {
                    Trace.WriteLine(string.Format("{0}: Failed to write to channel", DateTime.UtcNow));
                }
                else
                {
                    MoveBoundingBox(boundingBox);
                    UpdateLineColor(boundingBox);
                    UpdateFillColor(boundingBox);
                    UpdateLineThickness(boundingBox);

                    UpdateTextValue(description);
                    UpdateFontFamily(description);
                    UpdateTextDecoration(description);
                    UpdateTextColor(description);
                    UpdateTextSize(description);
                    UpdateTextPosition(description, boundingBox);

                    Invoke((MethodInvoker)(() =>
                    {
                        textMetadata.Text = _metadataSerializer.WriteMetadataXml(metadata);
                        textBoxTime.Text = DateTime.Now.ToString("HH.mm.ss:fff");
                    }));
                }

                Thread.Sleep(_timeBetweenMetadata);
            }
        }