Example #1
0
 public void GetLocalPosition_ShouldReturnLocalPosition_When_ImageSizeIsNotSpecified(int width, int height, int x, int y, int z, RotationAngle imageRotation, bool isMirrored, float expectedX, float expectedY, float expectedZ)
 {
     WithRectTransform((rectTransform) => {
         rectTransform.sizeDelta = new Vector2(width, height);
         var result = ImageCoordinate.GetLocalPosition(rectTransform, x, y, z, imageRotation, isMirrored);
         Assert.AreEqual(new Vector3(expectedX, expectedY, expectedZ), result);
     });
 }
Example #2
0
        public void ImageToPoint_ShouldReturnLocalPoint_When_ImageSizeIsSameAsScreenSize(int width, int height, int x, int y, int z, RotationAngle imageRotation, bool isMirrored,
                                                                                         float expectedX, float expectedY, float expectedZ)
        {
            var rect   = BuildRect(-width / 2, width / 2, -height / 2, height / 2);
            var result = ImageCoordinate.ImageToPoint(rect, x, y, z, width, height, imageRotation, isMirrored);

            Assert.AreEqual(new Vector3(expectedX, expectedY, expectedZ), result);
        }
Example #3
0
 public void GetLocalPositionNormalized_ShouldScaleZ_When_ZScaleIsSpecified(int width, int height, float normalizedX, float normalizedY, float normalizedZ, float zScale, RotationAngle imageRotation, bool isMirrored, float expectedZ)
 {
     WithRectTransform((rectTransform) => {
         rectTransform.sizeDelta = new Vector2(width, height);
         var result = ImageCoordinate.GetLocalPositionNormalized(rectTransform, normalizedX, normalizedY, normalizedZ, zScale, imageRotation, isMirrored);
         Assert.AreEqual(expectedZ, result.z);
     });
 }
Example #4
0
        public void ImageNormalizedToPoint_ShouldReturnLocalPoint_When_ZScaleIsSpecified(int width, int height, float normalizedX, float normalizedY, float normalizedZ, float zScale,
                                                                                         RotationAngle imageRotation, bool isMirrored, float expectedZ)
        {
            var rect   = BuildRect(-width / 2, width / 2, -height / 2, height / 2);
            var result = ImageCoordinate.ImageNormalizedToPoint(rect, normalizedX, normalizedY, normalizedZ, zScale, imageRotation, isMirrored);

            Assert.AreEqual(expectedZ, result.z);
        }
Example #5
0
        public void ImageNormalizedToPoint_ShouldReturnLocalPoint_When_TheAnchorOfRectIsNotAtTheCenter(float normalizedX, float normalizedY, float normalizedZ, float xMin, float xMax, float yMin, float yMax,
                                                                                                       RotationAngle imageRotation, bool isMirrored, float expectedX, float expectedY, float expectedZ)
        {
            var rect   = BuildRect(xMin, xMax, yMin, yMax);
            var result = ImageCoordinate.ImageNormalizedToPoint(rect, normalizedX, normalizedY, normalizedZ, imageRotation, isMirrored);

            Assert.AreEqual(new Vector3(expectedX, expectedY, expectedZ), result);
        }
Example #6
0
        public void ImageNormalizedToPoint_ShouldReturnLocalPoint_When_TheAnchorOfRectIsAtTheCenter(int width, int height, float normalizedX, float normalizedY, float normalizedZ,
                                                                                                    RotationAngle imageRotation, bool isMirrored, float expectedX, float expectedY, float expectedZ)
        {
            var rect   = BuildRect(-width / 2, width / 2, -height / 2, height / 2);
            var result = ImageCoordinate.ImageNormalizedToPoint(rect, normalizedX, normalizedY, normalizedZ, imageRotation, isMirrored);

            Assert.AreEqual(new Vector3(expectedX, expectedY, expectedZ), result);
        }
Example #7
0
        public void ImageToPoint_ShouldReturnLocalPoint_When_TheAnchorOfRectIsNotAtTheCenter(int width, int height, int x, int y, float xMin, float xMax, float yMin, float yMax,
                                                                                             RotationAngle imageRotation, bool isMirrored, float expectedX, float expectedY)
        {
            var rect   = BuildRect(xMin, xMax, yMin, yMax);
            var result = ImageCoordinate.ImageToPoint(rect, x, y, width, height, imageRotation, isMirrored);

            Assert.AreEqual(new Vector3(expectedX, expectedY, 0), result);
        }
Example #8
0
        /// <param name="threshold">
        ///   Score threshold. This value must be between 0 and 1.
        ///   This will affect the rectangle's color. For example, if the score is below the threshold, the rectangle will be transparent.
        ///   The default value is 0.
        /// </param>
        public void Draw(Detection target, float threshold = 0.0f)
        {
            if (ActivateFor(target))
            {
                var score = target.Score.Count > 0 ? target.Score[0] : 1.0f;
                var color = GetColor(score, Mathf.Clamp(threshold, 0.0f, 1.0f));

                // Assume that location data's format is always RelativeBoundingBox
                // TODO: fix if there are cases where this assumption is not correct.
                var rectVertices = GetAnnotationLayer().GetRectVertices(target.LocationData.RelativeBoundingBox, rotationAngle, isMirrored);
                locationData.SetColor(GetColor(score, Mathf.Clamp(threshold, 0.0f, 1.0f)));
                locationData.Draw(rectVertices);

                var width      = rectVertices[2].x - rectVertices[0].x;
                var height     = rectVertices[2].y - rectVertices[0].y;
                var labelText  = target.Label.Count > 0 ? target.Label[0] : null;
                var vertexId   = ((int)rotationAngle / 90 + 1) % 4;
                var isInverted = ImageCoordinate.IsInverted(rotationAngle);
                var(maxWidth, maxHeight) = isInverted ? (height, width) : (width, height);
                label.Draw(labelText, rectVertices[vertexId], color, maxWidth, maxHeight);

                relativeKeypoints.Draw(target.LocationData.RelativeKeypoints);
            }
        }