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); }