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 }; _currentDirection = MovementDirected.Up; double gpsAltitiude = 0.0; while (token.IsCancellationRequested == false) { SendBoundingBoxData(boundingBox, dummyCenterOfGravity); SendGpsData(ref gpsAltitiude); SendNonStandardData(); Thread.Sleep(_timeBetweenMetadata); } }
private void MoveBoundingBox(Rectangle boundingBox) { switch (_currentDirection) { case MovementDirected.Up: boundingBox.Top += StepSize; boundingBox.Bottom += StepSize; if (boundingBox.Top >= TopLimit) { _currentDirection = MovementDirected.Right; } break; case MovementDirected.Right: boundingBox.Right += StepSize; boundingBox.Left += StepSize; if (boundingBox.Right >= RightLimit) { _currentDirection = MovementDirected.Down; } break; case MovementDirected.Down: boundingBox.Top -= StepSize; boundingBox.Bottom -= StepSize; if (boundingBox.Bottom <= BottomLimit) { _currentDirection = MovementDirected.Left; } break; case MovementDirected.Left: boundingBox.Right -= StepSize; boundingBox.Left -= StepSize; if (boundingBox.Left <= LeftLimit) { _currentDirection = MovementDirected.Up; } break; } }
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); } }