/// <summary> /// Constructs the calibration parameters object. /// No calibration data is guaranteed until the DLL which supplies the data does. /// </summary> private void ConstructCalibrationParameters(MetaFactoryPackage package) { CalibrationParameters pars = new CalibrationParameters(new CalibrationParameterLoaderAdditionalMatrices()); package.MetaContext.Add(pars); package.EventReceivers.Add(pars); }
private void ImportCameraModel() { CalibrationParameters pars = metaContext.Get <CalibrationParameters>(); if (pars.Profiles.ContainsKey(_key)) //check if the dict has the key for the calibration you're after. { CalibrationProfile profile = pars.Profiles[_key]; //get the calibration _cameraModel = profile.CameraModel; UpdateParameters(); } }
/// <summary> /// Register when Calibration parameters are ready /// </summary> private void Start() { _poseMatrix = Matrix4x4.identity; //Get the module from the metaContext CalibrationParameters pars = metaContext.Get <CalibrationParameters>(); if (pars != null) //the metaContext may not have the module if it was not loaded correctly. { //Will be called when the parameters have been loaded. pars.OnParametersReady += CalibratePose; } }
/// <summary> /// Accesses the context and registers the parameter fetching delegate. /// </summary> private void Start() { SetOpenGLMatrix(); //Get the module from the metaContext CalibrationParameters pars = metaContext.Get <CalibrationParameters>(); if (pars != null) //the metaContext may not have the module if it was not loaded correctly. { //Will be called when the parameters have been loaded. pars.OnParametersReady += ImportCameraModel; } }
/// <summary> /// Import the Pose from Calibration Parameters /// </summary> public void CalibratePose() { CalibrationParameters pars = metaContext.Get <CalibrationParameters>(); // Remove from event pars.OnParametersReady -= CalibratePose; if (pars.Profiles.ContainsKey(_key)) //check if the dict has the key for the calibration you're after. { CalibrationProfile profile = pars.Profiles[_key]; //get the calibration _poseMatrix = profile.RelativePose; UpdatePose(); } }
public Dictionary <string, CalibrationProfile> Load() { _delay--; if (_delay > 0) { return(null); } string jsonString = "[{\"relative_pose\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], \"name\": \"rbg0\", \"camera_model\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]}, {\"relative_pose\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], \"name\": \"rbg1\", \"camera_model\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]}, {\"relative_pose\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], \"name\": \"rbg2\", \"camera_model\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]}, {\"relative_pose\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], \"name\": \"rbg3\", \"camera_model\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]}, {\"relative_pose\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], \"name\": \"rbg4\", \"camera_model\": [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]}]"; var JsonRootNode = JSON.Parse(jsonString); var nodes = JsonRootNode.AsArray; Dictionary <string, CalibrationProfile> profiles = new Dictionary <string, CalibrationProfile>(); int nodeCounter = 0; foreach (JSONNode n in nodes) { string name = null; try { name = n["name"]; double[] relativePose = n["relative_pose"].AsArray.Childs.Select(d => Double.Parse(d)).ToArray(); //double[] cameraModel = n["camera_model"].AsArray.Childs.Select(d => Double.Parse(d)).ToArray(); profiles.Add(name, new CalibrationProfile { /*CameraModel = cameraModel,*/ RelativePose = CalibrationParameters.MatrixFromArray(relativePose) }); } catch { if (name != null) { Debug.LogError(string.Format("CalibrationParameter parsing error: node named '{0}' was not formatted correctly.", name)); } else { Debug.LogError(string.Format("CalibrationParameter parsing error: node {0} was not formatted correctly.", nodeCounter)); } } nodeCounter++; } return(profiles); }
public virtual Dictionary <string, CalibrationProfile> Load() { string jsonString = ParseDllInput(); if (jsonString == null) { return(null); } var JsonRootNode = JSON.Parse(jsonString); if (JsonRootNode == null) { return(null); } var nodes = JsonRootNode.AsArray; Dictionary <string, CalibrationProfile> profiles = new Dictionary <string, CalibrationProfile>(); int nodeCounter = 0; foreach (JSONNode n in nodes) { string name = null; try { name = n["name"]; Matrix4x4 poseMat = Matrix4x4.zero; double[] r = n["relative_pose"].AsArray.Childs.Select(d => Double.Parse(d)).ToArray(); if (r.Length < 12) { Debug.LogError("CalibrationParameterLoader: array was too short."); } else { poseMat = CalibrationParameters.MatrixFromArray(r); } double[] cameraModel = n["camera_model"].AsArray.Childs.Select(d => Double.Parse(d)).ToArray(); profiles.Add(name, new CalibrationProfile { RelativePose = poseMat, CameraModel = cameraModel }); // Debug.Log(profiles[name].RelativePose + "|||" + // string.Join(" ", (profiles[name].CameraModel.Select(x => x.ToString())).ToArray())); } catch { if (name != null) { Debug.LogError( string.Format( "CalibrationParameter parsing error: node named '{0}' was not formatted correctly.", name)); } else { Debug.LogError( string.Format("CalibrationParameter parsing error: node {0} was not formatted correctly.", nodeCounter)); } } nodeCounter++; } return(profiles); }