示例#1
0
    void Create(int markerId)
    {
        ValidMarkerImage();

        Dictionary dictionary = Aruco.getPredefinedDictionary(dictionaryId);

        Aruco.drawMarker(dictionary, markerId, markerSize, markerImage);

        Utils.matToTexture2D(markerImage, texture, true, 0, true);

        imageQrCode.texture = texture;
    }
示例#2
0
        // Use this for initialization
        void Start()
        {
            Dictionary dictionary = Aruco.getPredefinedDictionary(dictionaryId);

            Mat markerImg = new Mat();

            Aruco.drawMarker(dictionary, markerId, markerSize, markerImg, borderBits);

            Debug.Log("markerImg.ToString() " + markerImg.ToString());

            Texture2D texture = new Texture2D(markerImg.cols(), markerImg.rows(), TextureFormat.RGBA32, false);

            Utils.matToTexture2D(markerImg, texture);

            gameObject.GetComponent <Renderer> ().material.mainTexture = texture;

            //save markerImg
//                      string savePath = Application.persistentDataPath + "/marker_id" + markerId + ".jpg";
//                      Debug.Log ("savePath " + savePath);
//                      Imgcodecs.imwrite (savePath, markerImg);
        }
示例#3
0
        private void CreateMaeker()
        {
            if (markerImg.cols() != markerSize)
            {
                markerImg.Dispose();
                markerImg = new Mat(markerSize, markerSize, CvType.CV_8UC3);
                texture   = new Texture2D(markerImg.cols(), markerImg.rows(), TextureFormat.RGB24, false);
            }
            else
            {
                markerImg.setTo(Scalar.all(255));
            }

            gameObject.transform.localScale = new Vector3(markerImg.cols(), markerImg.rows(), 1);

            float width  = markerImg.width() / 0.7f;
            float height = markerImg.height() / 0.7f;

            float widthScale  = (float)Screen.width / width;
            float heightScale = (float)Screen.height / height;

            if (widthScale < heightScale)
            {
                Camera.main.orthographicSize       = (width * (float)Screen.height / (float)Screen.width) / 2;
                gameObject.transform.localPosition = new Vector3(0, -height * 0.1f, 0);
            }
            else
            {
                Camera.main.orthographicSize       = height / 2;
                gameObject.transform.localPosition = new Vector3(width * 0.1f, 0, 0);
            }

            // create dictinary.
            Dictionary dictionary = Aruco.getPredefinedDictionary((int)dictionaryId);

            // draw marker.
            switch (markerType)
            {
            default:
            case MarkerType.CanonicalMarker:
                Aruco.drawMarker(dictionary, (int)markerId, markerSize, markerImg, borderBits);
                Debug.Log("draw CanonicalMarker: " + "dictionaryId " + (int)dictionaryId + " markerId " + (int)markerId + " sidePixels " + markerSize + " borderBits " + borderBits);
                break;

            case MarkerType.GridBoard:
                GridBoard gridBoard = GridBoard.create(gridBoradMarkersX, gridBoradMarkersY, gridBoradMarkerLength, gridBoradMarkerSeparation, dictionary, gridBoradMarkerFirstMarker);
                gridBoard.draw(new Size(markerSize, markerSize), markerImg, gridBoradMarginSize, borderBits);
                gridBoard.Dispose();
                Debug.Log("draw GridBoard: " + "markersX " + gridBoradMarkersX + " markersY " + gridBoradMarkersY + " markerLength " + gridBoradMarkerLength +
                          " markerSeparation " + gridBoradMarkerSeparation + "dictionaryId " + (int)dictionaryId + " outSize " + markerSize + " marginSize " + gridBoradMarginSize + " borderBits " + borderBits);
                break;

            case MarkerType.ChArUcoBoard:
                CharucoBoard charucoBoard = CharucoBoard.create(chArUcoBoradMarkersX, chArUcoBoradMarkersY, chArUcoBoradSquareLength, chArUcoBoradMarkerLength, dictionary);
                charucoBoard.draw(new Size(markerSize, markerSize), markerImg, chArUcoBoradMarginSize, borderBits);
                charucoBoard.Dispose();
                Debug.Log("draw ChArUcoBoard: " + "markersX " + chArUcoBoradMarkersX + " markersY " + chArUcoBoradMarkersY + " markerLength " + chArUcoBoradSquareLength +
                          " markerSeparation " + chArUcoBoradMarkerLength + "dictionaryId " + (int)dictionaryId + " outSize " + markerSize + " marginSize " + chArUcoBoradMarginSize + " borderBits " + borderBits);
                break;
            }

            Utils.matToTexture2D(markerImg, texture);
        }