/// <summary>
        /// Raises the web cam texture to mat helper initialized event.
        /// </summary>
        public void OnFrameToMatHelperInitialized()
        {
            Debug.Log("OnFrameToMatHelperInitialized");

            OpenCvSharp.Mat webCamTextureMat = _frameToMatHelper.GetMat();

            _previewTex2d = new Texture2D(webCamTextureMat.Width, webCamTextureMat.Height, TextureFormat.RGBA32, false);

            _rgbMat = new OpenCvSharp.Mat(webCamTextureMat.Rows, webCamTextureMat.Cols, OpenCvSharp.MatType.CV_8UC3);

            gameObject.transform.localScale = new Vector3(webCamTextureMat.Width, webCamTextureMat.Height, 1);

            float width  = webCamTextureMat.Width;
            float height = webCamTextureMat.Height;

            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;
            }
            else
            {
                Camera.main.orthographicSize = height / 2;
            }
            _frameRendere = gameObject.GetComponent <Renderer>();
            _frameRendere.material.mainTexture = _previewTex2d;


            //if WebCamera is frontFaceing,flip Mat.
            if (_frameToMatHelper.GetWebCamDevice().isFrontFacing)
            {
                _frameToMatHelper.FlipHorizontal = true;
            }


            int patternWidth = (int)(Mathf.Min(webCamTextureMat.Width, webCamTextureMat.Height) * 0.8f);

            _patternRect = new OpenCvSharp.Rect(webCamTextureMat.Width / 2 - patternWidth / 2, webCamTextureMat.Height / 2 - patternWidth / 2, patternWidth, patternWidth);
        }
示例#2
0
        public void OnFrameToMatHelperInitialized()
        {
            Debug.Log("OnFrameToMatHelperInitialized");

            Mat webCamTextureMat = _frameToMatHelper.GetMat();

            _targetPatternTex2d = new Texture2D(200, 200);

            _previewTex2d  = new Texture2D(webCamTextureMat.Width, webCamTextureMat.Height, TextureFormat.RGBA32, false);
            _frameRenderer = gameObject.GetComponent <Renderer>();
            _frameRenderer.material.mainTexture = _previewTex2d;

            _grayMat = new Mat(webCamTextureMat.Rows, webCamTextureMat.Cols, MatType.CV_8UC1);

            gameObject.transform.localScale = new Vector3(webCamTextureMat.Width, webCamTextureMat.Height, 1);

            Debug.Log("Screen.width " + Screen.width + " Screen.height " + Screen.height + " Screen.orientation " + Screen.orientation);


            float width  = webCamTextureMat.Width;
            float height = webCamTextureMat.Height;

            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;
            }
            else
            {
                Camera.main.orthographicSize = height / 2;
            }

            //if WebCamera is frontFaceing,flip Mat.
            if (_frameToMatHelper.GetWebCamDevice().isFrontFacing)
            {
                _frameToMatHelper.FlipHorizontal = true;
            }
            StartCoroutine(DetectorFrames());
        }