// 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()
        {
            isShowingAxesToggle.isOn = isShowingAxes;
            axes.SetActive(isShowingAxes);
            isShowingCubeToggle.isOn = isShowingCube;
            cube.SetActive(isShowingCube);
            isShowingVideoToggle.isOn = isShowingVideo;
            video.SetActive(isShowingVideo);

            ARGameObject.gameObject.SetActive(false);



            webCamTextureToMatHelper = gameObject.GetComponent <WebCamTextureToMatHelper> ();

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

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

                Texture2D patternTexture = new Texture2D(patternMat.width(), patternMat.height(), TextureFormat.RGBA32, false);
                Utils.matToTexture2D(patternMat, patternTexture);
                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.Init();
            }
        }
 /// <summary>
 /// Raises the change camera button event.
 /// </summary>
 public void OnChangeCameraButton()
 {
     webCamTextureToMatHelper.Init(null, webCamTextureToMatHelper.requestWidth, webCamTextureToMatHelper.requestHeight, !webCamTextureToMatHelper.requestIsFrontFacing);
 }