Example #1
0
        /// <summary>
        /// Draws the connection line between two items and also the lenght
        /// </summary>
        /// <param name="uiImage"></param>
        /// <param name="item"></param>
        /// <param name="item2"></param>
        public void DrawLineFromItemToItem(Mat uiImage, YoloItem item, YoloItem item2, out Line line)
        {
            var startPoint = new OpenCvSharp.Point(item.Center().X *SCALE, item.Center().Y *SCALE);
            var endPoint   = new OpenCvSharp.Point(item2.Center().X *SCALE, item2.Center().Y *SCALE);

            line = new Line()
            {
                X1 = item.Center().X *SCALE,
                Y1 = item.Center().Y *SCALE,
                X2 = item2.Center().X *SCALE,
                Y2 = item2.Center().Y *SCALE
            };

            // Draw the line
            Cv2.Line(uiImage,
                     startPoint,
                     endPoint,
                     Scalar.Red, 2);

            // Draw distance and length
            // Casting from points to points is really annoying... TODO: Refactor that.
            var sysStartPoint = new System.Windows.Point(startPoint.X, startPoint.Y);
            var sysEndPoint   = new System.Windows.Point(endPoint.X, endPoint.Y);
            var distance      = GeometryHelper.Distance(sysStartPoint, sysEndPoint);
            var length        = distance * coordinateLength;
            var centerOfLine  = GeometryHelper.GetCenterOfLine(sysStartPoint, sysEndPoint);

            // Put text in it.
            DrawTextblockWithBackground(
                uiImage,
                centerOfLine,
                $"{string.Format("{0:0.00}", length)}m",
                Scalar.Red
                );
        }
 public void SetTrackingObject(YoloItem trackingObject)
 {
     this._trackingObject = trackingObject.Center();
 }