// Use this for initialization
        void Start()
        {
//            Utils.setDebugMode(true);

            using (Mat patternMat = Imgcodecs.imread(Application.persistentDataPath + "/patternImg.jpg")) {
                if (patternMat.total() == 0)
                {
                    patternRawImage.gameObject.SetActive(false);
                }
                else
                {
                    Imgproc.cvtColor(patternMat, patternMat, Imgproc.COLOR_BGR2RGB);

                    Texture2D patternTexture = new Texture2D(patternMat.width(), patternMat.height(), TextureFormat.RGBA32, false);

                    Utils.matToTexture2D(patternMat, patternTexture);

                    patternRawImage.texture = patternTexture;
                    patternRawImage.rectTransform.localScale = new Vector3(1.0f, (float)patternMat.height() / (float)patternMat.width(), 1.0f);

                    patternRawImage.gameObject.SetActive(true);
                }
            }

            webCamTextureToMatHelper = gameObject.GetComponent <WebCamTextureToMatHelper> ();
            webCamTextureToMatHelper.Init();


            detector = ORB.create();
            detector.setMaxFeatures(1000);
            keypoints = new MatOfKeyPoint();
        }
Ejemplo n.º 2
0
        // Use this for initialization
        void Start()
        {
            displayAxesToggle.isOn = displayAxes;
            axes.SetActive(displayAxes);
            displayCubeToggle.isOn = displayCube;
            cube.SetActive(displayCube);
            displayVideoToggle.isOn = displayVideo;
            video.SetActive(displayVideo);

            ARGameObject.gameObject.SetActive(false);

            webCamTextureToMatHelper = gameObject.GetComponent <WebCamTextureToMatHelper>();

            patternMat = Imgcodecs.imread(Application.persistentDataPath + "/patternImg.jpg");

            if (patternMat.total() == 0)
            {
                OnCapturePatternButtonClick();
            }
            else
            {
                Imgproc.cvtColor(patternMat, patternMat, Imgproc.COLOR_BGR2RGB);

                Texture2D patternTexture = new Texture2D(patternMat.width(), patternMat.height(), TextureFormat.RGBA32, false);

                //To reuse mat, set the flipAfter flag to true.
                Utils.matToTexture2D(patternMat, patternTexture, true, 0, true);
                Debug.Log("patternMat dst ToString " + patternMat.ToString());

                patternRawImage.texture = patternTexture;
                patternRawImage.rectTransform.localScale = new Vector3(1.0f, (float)patternMat.height() / (float)patternMat.width(), 1.0f);

                pattern             = new Pattern();
                patternTrackingInfo = new PatternTrackingInfo();

                patternDetector = new PatternDetector(null, null, null, true);

                patternDetector.buildPatternFromImage(patternMat, pattern);
                patternDetector.train(pattern);


                webCamTextureToMatHelper.Initialize();
            }
        }