Beispiel #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);
        }
Beispiel #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];
            }
        }
Beispiel #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);
        }
Beispiel #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);
 }