Exemplo n.º 1
0
        bool AdaptResources()
        {
            int w = _cameraTexture.width;
            int h = _cameraTexture.height;

            if (_processedCameraTexture != null && _processedCameraTexture.width == w && _processedCameraTexture.height == h)
            {
                return(true);
            }


            bool intrinsicsConversionSuccess = _cameraIntrinsics.ToOpenCV(ref _sensorMat, ref _distortionCoeffsMat, w, h);

            if (!intrinsicsConversionSuccess)
            {
                return(false);
            }
            _cameraIntrinsics.ApplyToCamera(_mainCamera);

            _projectorIntrinsicsCalibrator = new IntrinsicsCalibrator(w, h);

            _camTexGrayMat             = new Mat(h, w, CvType.CV_8UC1);
            _camTexGrayUndistortMat    = new Mat(h, w, CvType.CV_8UC1);
            _camTexGrayUndistortInvMat = new Mat(h, w, CvType.CV_8UC1);

            _processedCameraTexture      = new Texture2D(w, h, GraphicsFormat.R8_UNorm, 0, TextureCreationFlags.None);
            _processedCameraTexture.name = "ProcessedCameraTex";

            _arTexture      = new RenderTexture(w, h, 16, GraphicsFormat.R8G8B8A8_UNorm);
            _arTexture.name = "AR Texture";

            // Update circle pattern size.
            UpdateCirclePatternSize();

            // Create undistort map.
            Calib3d.initUndistortRectifyMap(_sensorMat, _distortionCoeffsMat, new Mat(), _sensorMat, new Size(_cameraTexture.width, _cameraTexture.height), CvType.CV_32FC1, _undistortMap1, _undistortMap2);

            // Start with a fixed projector FOV.
            //UpdateProjectorFOVManually( 1 );

            // Switch state.
            SwitchState(State.BlindCalibration);

            // Update UI.
            _processedCameraImage.texture = _processedCameraTexture;
            _arImage.texture = _arTexture;
            _cameraAspectFitter.aspectRatio = w / (float)h;
            _mainCamera.targetTexture       = _arTexture;

            return(true);
        }
Exemplo n.º 2
0
        void AdaptResources()
        {
            int w = _cameraTexture.width;
            int h = _cameraTexture.height;

            if (_processedCameraTexture != null && _processedCameraTexture.width == w && _processedCameraTexture.height == h)
            {
                return;
            }

            // Start over again.
            Reset();

            _intrinsicsCalibrator = new IntrinsicsCalibrator(w, h);

            // Create mats and textures.
            _camTexGrayMat                   = new Mat(h, w, CvType.CV_8UC1);
            _camTexGrayUndistortMat          = new Mat(h, w, CvType.CV_8UC1);
            _processedCameraTexture          = new Texture2D(w, h, GraphicsFormat.R8_UNorm, 0, TextureCreationFlags.None);
            _processedCameraTexture.name     = "UndistortedCameraTex";
            _processedCameraTexture.wrapMode = TextureWrapMode.Repeat;
            _arTexture      = new RenderTexture(w, h, 16, GraphicsFormat.R8G8B8A8_UNorm);
            _arTexture.name = "AR Texture";

            // Change state.
            if (_state == State.Initiating)
            {
                SwitchState(State.Calibrating);
            }

            // Update UI.
            _aspectFitter.aspectRatio     = w / (float)h;
            _processedCameraImage.texture = _processedCameraTexture;
            _arImage.texture          = _arTexture;
            _mainCamera.targetTexture = _arTexture;
        }