예제 #1
0
            // Methods

            /// <summary>
            /// Create the image and the image texture of the <see cref="ArucoObject"/>.
            /// </summary>
            public virtual void Create()
            {
                Cv.Mat image = null;
                ImageTexture = null;

                // In case of a marker
                ArucoMarker marker = ArucoObject as ArucoMarker;

                if (marker != null)
                {
                    marker.Dictionary.DrawMarker(marker.MarkerId, (int)marker.MarkerSideLength, out image, marker.MarkerBorderBits);
                }

                // In case of a grid board
                ArucoGridBoard arucoGridBoard = ArucoObject as ArucoGridBoard;

                if (arucoGridBoard != null)
                {
                    Aruco.GridBoard gridBoard = arucoGridBoard.Board as Aruco.GridBoard;
                    gridBoard.Draw(arucoGridBoard.ImageSize, out image, arucoGridBoard.MarginsSize, arucoGridBoard.MarkerBorderBits);
                }

                // In case of a charuco board
                ArucoCharucoBoard arucoCharucoBoard = ArucoObject as ArucoCharucoBoard;

                if (arucoCharucoBoard != null)
                {
                    Aruco.CharucoBoard charucoBoard = arucoCharucoBoard.Board as Aruco.CharucoBoard;
                    charucoBoard.Draw(arucoCharucoBoard.ImageSize, out image, arucoCharucoBoard.MarginsSize, arucoCharucoBoard.MarkerBorderBits);
                }

                // In case of a diamond
                ArucoDiamond diamond = ArucoObject as ArucoDiamond;

                if (diamond != null && diamond.Ids.Length == 4)
                {
                    Cv.Vec4i ids = new Cv.Vec4i();
                    for (int i = 0; i < diamond.Ids.Length; ++i)
                    {
                        ids.Set(i, diamond.Ids[i]);
                    }
                    Aruco.DrawCharucoDiamond(diamond.Dictionary, ids, (int)diamond.SquareSideLength, (int)diamond.MarkerSideLength, out image);
                }

                // Set the properties
                Image = image;
                if (Image != null)
                {
                    // Vertical flip to correctly display the image on the texture
                    int    verticalFlipCode = 0;
                    Cv.Mat imageForTexture  = Image.Clone();
                    Cv.Flip(imageForTexture, imageForTexture, verticalFlipCode);

                    // Load the image to the texture
                    int markerDataSize = (int)(Image.ElemSize() * Image.Total());
                    ImageTexture = new Texture2D(Image.Cols, Image.Rows, TextureFormat.RGB24, false);
                    ImageTexture.LoadRawTextureData(imageForTexture.DataIntPtr, markerDataSize);
                    ImageTexture.Apply();
                }
            }
예제 #2
0
        // ArucoObject methods

        public override Cv.Mat Draw()
        {
#if UNITY_EDITOR
            if (!UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode && (MarkerSideLength <= 0 || SquareSideLength <= 0 ||
                                                                                 SquareSideLength <= MarkerSideLength || Dictionary == null))
            {
                return(null);
            }
#endif
            Cv.Vec4i ids = new Cv.Vec4i();
            for (int i = 0; i < Ids.Length; ++i)
            {
                ids.Set(i, Ids[i]);
            }

            Cv.Mat image;
            Aruco.DrawCharucoDiamond(Dictionary, ids, GetInPixels(SquareSideLength), GetInPixels(MarkerSideLength), out image);

            return(image);
        }