private OnvifObject CreateOnvifObject(float x, float y, float area, string n, int id, int width, int height) { area /= scaleArea; float r_x = (float)Reciprocal(width); float r_y = (float)Reciprocal(height); float r_xx = r_x * 2; float r_yy = r_y * 2; var centerOfGravity = new Vector { X = x, Y = y }; var blob = new OnvifObject(id) { Appearance = new VideoOS.Platform.Metadata.Appearance { Shape = new Shape { BoundingBox = new VideoOS.Platform.Metadata.Rectangle { Bottom = height - y - area / 2, Left = x - area / 2, Top = height - y + area / 2, Right = x + area / 2 }, CenterOfGravity = centerOfGravity }, Description = new DisplayText { Value = n }, Transformation = new Transformation { Translate = new Vector { X = -1, Y = -1 }, Scale = new Vector { X = r_xx, Y = r_yy } } } }; return(blob); }
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); } }
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); } }