示例#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
            // Methods

            /// <summary>
            /// Create the image and the image texture of the <see cref="ArucoObject"/>.
            /// </summary>
            public virtual void Create()
            {
                Cv.Core.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.Core.Vec4i ids = new Cv.Core.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);
                }

                // Vertical flip to convert the image from Unity's left-handed coordinate system to OpenCV's right-handed coordinate system
                int verticalFlipCode = 0;

                Cv.Core.Flip(image, image, verticalFlipCode);

                // Set the properties
                Image = image;
                if (Image != null)
                {
                    int markerDataSize = (int)(Image.ElemSize() * Image.Total());
                    ImageTexture = new Texture2D(Image.cols, Image.rows, TextureFormat.RGB24, false);
                    ImageTexture.LoadRawTextureData(Image.dataIntPtr, markerDataSize);
                    ImageTexture.Apply();
                }
            }
示例#3
0
            // ArucoBoard methods

            public override Cv.Mat Draw()
            {
#if UNITY_EDITOR
                if (!UnityEditor.EditorApplication.isPlayingOrWillChangePlaymode && (MarkersNumberX <= 0 || MarkersNumberY <= 0 || MarkerSideLength <= 0 ||
                                                                                     MarkerSeparation <= 0 || MarkerBorderBits <= 0))
                {
                    return(null);
                }
#endif
                int             markerSideLength = GetInPixels(MarkerSideLength);
                int             markerSeparation = GetInPixels(MarkerSeparation);
                Aruco.GridBoard board            = Aruco.GridBoard.Create(MarkersNumberX, MarkersNumberY, markerSideLength, markerSeparation, Dictionary);

                Cv.Size imageSize = new Cv.Size();
                imageSize.Width  = GetInPixels(MarkersNumberX * (markerSideLength + markerSeparation) - markerSeparation + 2 * MarginsLength);
                imageSize.Height = GetInPixels(MarkersNumberY * (markerSideLength + markerSeparation) - markerSeparation + 2 * MarginsLength);

                Cv.Mat image;
                board.Draw(imageSize, out image, MarginsLength, (int)MarkerBorderBits);

                return(image);
            }