void ValidateForegroundLabeling(GameObject[] foregroundObjects, PerceptionCamera perceptionCamera) { if (perceptionCamera.LabelingConfiguration == null) { Debug.LogError("PerceptionCamera does not have a labeling configuration. This will likely cause the program to fail."); return; } var labelingConfiguration = perceptionCamera.LabelingConfiguration; var regex = new Regex(".*_[0-9][0-9]"); var foregroundNames = foregroundObjects.Select(f => { var foregroundName = f.name; if (regex.IsMatch(foregroundName)) { foregroundName = foregroundName.Substring(0, foregroundName.Length - 3); } return(foregroundName); }).ToList(); var foregroundObjectsMissingFromConfig = foregroundNames.Where(f => labelingConfiguration.LabelEntries.All(l => l.label != f)).ToList(); var configurationsMissingModel = labelingConfiguration.LabelEntries.Skip(1).Select(l => l.label).Where(l => !foregroundNames.Any(f => f == l)).ToList(); if (foregroundObjectsMissingFromConfig.Count > 0) { Debug.LogError($"The following foreground models are not present in the LabelingConfiguration: {string.Join(", ", foregroundObjectsMissingFromConfig)}"); } if (configurationsMissingModel.Count > 0) { Debug.LogError($"The following LabelingConfiguration entries do not correspond to any foreground object model: {string.Join(", ", configurationsMissingModel)}"); } }
void ValidateForegroundLabeling(GameObject[] foregroundObjects, PerceptionCamera perceptionCamera) { var boundingBox2DLabeler = (BoundingBox2DLabeler)perceptionCamera.labelers.First(l => l is BoundingBox2DLabeler); if (boundingBox2DLabeler == null) { return; } var labelConfig = boundingBox2DLabeler.idLabelConfig; if (labelConfig == null) { Debug.LogError("PerceptionCamera does not have a labeling configuration. This will likely cause the program to fail."); return; } var foregroundObjectsMissingFromConfig = new List <GameObject>(); var foundLabels = new List <string>(); foreach (var foregroundObject in foregroundObjects) { var labeling = foregroundObject.GetComponent <Labeling>(); if (labeling == null) { foregroundObjectsMissingFromConfig.Add(foregroundObject); continue; } bool found = false; foreach (var label in labeling.labels) { if (labelConfig.labelEntries.Select(e => e.label).Contains(label)) { foundLabels.Add(label); found = true; break; } } if (!found) { foregroundObjectsMissingFromConfig.Add(foregroundObject); } } if (foregroundObjectsMissingFromConfig.Count > 0) { Debug.LogError($"The following foreground models are not present in the LabelingConfiguration: {string.Join(", ", foregroundObjectsMissingFromConfig)}"); } var configurationsMissingModel = labelConfig.labelEntries.Select(l => l.label).Where(l => !foundLabels.Contains(l)).ToArray(); if (configurationsMissingModel.Length > 0) { Debug.LogError($"The following LabelingConfiguration entries do not correspond to any foreground object model: {string.Join(", ", configurationsMissingModel)}"); } }
GameObject SetupCamera(out PerceptionCamera perceptionCamera) { var cameraObject = new GameObject(); cameraObject.SetActive(false); var camera = cameraObject.AddComponent <Camera>(); camera.orthographic = true; camera.orthographicSize = 1; perceptionCamera = cameraObject.AddComponent <PerceptionCamera>(); perceptionCamera.captureRgbImages = false; AddTestObjectForCleanup(cameraObject); return(cameraObject); }