Ejemplo n.º 1
0
        /// <summary>
        ///   Renders a bounding box and its label on a screen.
        ///   It is assumed that the screen is vertical to terrain and not inverted.
        /// </summary>
        /// <param name="isFlipped">
        ///   if true, x axis is oriented from right to left (top-right point is (0, 0) and bottom-left is (1, 1))
        /// </param>
        /// <remarks>
        ///   In <paramref name="detection" />, y-axis is oriented from top to bottom.
        ///   Its location data is represented by relative bounding box.
        /// </remarks>
        public void Draw(Transform screenTransform, Detection detection, bool isFlipped = false)
        {
            if (detection.LocationData == null)
            {
                Clear();
                return;
            }

            DrawRectAndLabel(screenTransform, detection, isFlipped);
            DrawRelativeKeypoints(screenTransform, detection.LocationData.RelativeKeypoints, isFlipped);
        }
Ejemplo n.º 2
0
        private void DrawRectAndLabel(Transform screenTransform, Detection detection, bool isFlipped = false, bool isFiltered = false)
        {
            var positions = GetPositions(screenTransform, detection.LocationData.RelativeBoundingBox, isFlipped, isFiltered);

            gameObject.GetComponent <LineRenderer>().SetPositions(positions);

            if (detection.Label.Count > 0)
            {
                // TODO: change font size
                gameObject.GetComponent <TextMesh>().text = $" {detection.Label[0]}, {detection.Score[0]:G3}";
                gameObject.transform.position             = positions[0];
            }
        }
Ejemplo n.º 3
0
        public static Detection[] PtrToDetectionArray(MpDetectionVector detectionVectorPtr)
        {
            var detectionVector = Marshal.PtrToStructure <DetectionVector>(detectionVectorPtr);
            var detections      = new Detection[detectionVector.size];

            unsafe {
                var arr     = detectionVector.detections;
                var sizePtr = detectionVector.sizeList;

                for (var i = 0; i < detectionVector.size; i++)
                {
                    var size  = *sizePtr++;
                    var bytes = new byte[size];

                    Marshal.Copy((IntPtr)(*arr++), bytes, 0, size);

                    detections[i] = Detection.Parser.ParseFrom(bytes);
                }
            }

            return(detections);
        }
Ejemplo n.º 4
0
 /// <summary>
 ///   Renders a bounding box and its label on a screen.
 ///   It is assumed that the screen is vertical to terrain and not inverted.
 /// </summary>
 /// <param name="isFlipped">
 ///   if true, x axis is oriented from right to left (top-right point is (0, 0) and bottom-left is (1, 1))
 /// </param>
 /// <remarks>
 ///   In <paramref name="detection" />, y-axis is oriented from top to bottom.
 ///   Its location data is represented by relative bounding box.
 /// </remarks>
 public void Draw(Transform screenTransform, Detection detection, bool isFlipped = false)
 {
     DrawRectAndLabel(screenTransform, detection, isFlipped);
     DrawRelativeKeypoints(screenTransform, detection.LocationData.RelativeKeypoints, isFlipped);
 }