Beispiel #1
0
    void Update()
    {
        KinectManager kinectManager = KinectManager.Instance;

        if (cam != null && projConfig != null && kinectManager != null && kinectManager.IsInitialized())
        {
            if (kinectManager.autoHeightAngle == KinectManager.AutoHeightAngle.AutoUpdate ||
                kinectManager.autoHeightAngle == KinectManager.AutoHeightAngle.AutoUpdateAndShowInfo)
            {
                Matrix4x4 worldToLocal = RAT2Unity.Convert(projConfig.pose);
                worldToLocal = UnityUtilities.ConvertRHtoLH(worldToLocal);

                this.transform.localPosition = worldToLocal.ExtractTranslation() + new Vector3(0f, kinectManager.sensorHeight, 0f);
            }
        }
    }
Beispiel #2
0
//	void OnRenderImage (RenderTexture source, RenderTexture destination)
//	{
//		if(flipCameraX && camFlipMat)
//		{
//			Graphics.Blit(source, destination, camFlipMat);
//		}
//	}

    private void LoadCalibrationData()
    {
        projConfig = null;
        cam        = GetComponent <Camera>();

        if (!cam)
        {
            Debug.LogError("Please add the ProjectorCamera-component to a camera in the scene.");
            return;
        }

        if (calibrationXml)
        {
            ensemble = ProjectorCameraEnsemble.ReadCalibration(calibrationXml.text);

            foreach (ProjectorCameraEnsemble.Projector pc in ensemble.projectors)
            {
                if (pc.name == projNameInConfig)
                {
                    projConfig = pc;
                }
            }
        }
        else
        {
            projConfig = null;
        }

        if (projConfig != null)
        {
            if (displayIndex < 0)
            {
                displayIndex = projConfig.displayIndex;
                Debug.Log("ProjCam target display: " + displayIndex);

                if (useProjectorDisplay && displayIndex >= 0)
                {
//#if !UNITY_EDITOR
                    cam.targetDisplay = displayIndex;
//#endif
                }
            }

            //Debug.Log("Projective Rendering - Loading projector calibration information.");
            imageWidth  = projConfig.width;
            imageHeight = projConfig.height;

            if (imageWidth > 0 && imageHeight > 0 && projConfig.cameraMatrix != null)
            {
                cam.aspect = (float)imageWidth / imageHeight;

                // this is the vertical field of view - fy
                float fieldOfViewRad = 2.0f * (float)System.Math.Atan((((double)(imageHeight)) / 2.0) / projConfig.cameraMatrix[1, 1]);
                float fieldOfViewDeg = fieldOfViewRad / 3.14159265359f * 180.0f;

                cam.fieldOfView = fieldOfViewDeg;
                Debug.Log("ProjCam FOV: " + fieldOfViewDeg);

                Matrix4x4 opencvProjMat = GetProjectionMatrix(projConfig.cameraMatrix, cam.nearClipPlane, cam.farClipPlane);
                cam.projectionMatrix = UnityUtilities.ConvertRHtoLH(opencvProjMat);
            }

            if (projConfig.lensDistortion != null)
            {
                //var irCoef = projConfig.lensDistortion.AsFloatArray();
                //! jolaur -- looks like this is not being used and is now 2 elements instead of four in the new xml format
                //! lensDist = new Vector4(irCoef[0], irCoef[1], irCoef[2], irCoef[3]);
                //lensDist = new Vector4();
            }

            if (projConfig.pose != null)
            {
                Matrix4x4 worldToLocal = RAT2Unity.Convert(projConfig.pose);
                worldToLocal = UnityUtilities.ConvertRHtoLH(worldToLocal);

                KinectManager kinectManager = KinectManager.Instance;

                this.transform.localPosition = worldToLocal.ExtractTranslation() + new Vector3(0f, kinectManager.sensorHeight, 0f);
                this.transform.localRotation = worldToLocal.ExtractRotation();
                Debug.Log("ProjCam position: " + transform.localPosition + ", rotation: " + transform.localRotation.eulerAngles);
            }
        }
        else
        {
            Debug.LogError("Make sure the 'Calibration Xml' && 'Proj name in config'-settings are correct.");
            //lensDist = new Vector4();
        }
    }