/// <summary> /// Looks up the full path given the partial file name /// </summary> /// <param name="partialFileName">The partial file name, as might be given in one of the configuration files</param> /// <returns>null on error, otherwise the full path</returns> string CubeLightsPath(string partialFileName) { // See if the file name cache has been built if (null == cubeLightsPathCache) { // Construct a cross reference within the cube lights path var path = Path.Combine(cozmoResourcesPath, "config/engine/lights/cubeLights"); cubeLightsPathCache = FS.BuildNameToRelativePathXref(path); } // look up the file name for the foo return(cubeLightsPathCache.TryGetValue(partialFileName, out var fullPath) ? fullPath : null); }
/// <summary> /// Looks up the full path given the partial file name /// </summary> /// <param name="partialFileName">The partial file name, as might be given in one of the configuration files</param> /// <returns>null on error, otherwise the full path</returns> string AnimationGroupPath(string partialFileName) { // See if the file name cache has been built if (null == animationGroupsPathCache) { // Construct a cross reference within the animation groups path var path = Path.Combine(cozmoResourcesPath, "assets/animationGroups"); animationGroupsPathCache = FS.BuildNameToRelativePathXref(path); } // look up the file name for the foo return(animationGroupsPathCache.TryGetValue(partialFileName, out var fullPath) ? fullPath : null); }
/// <summary> /// Looks up the full path given the partial file name /// </summary> /// <param name="partialFileName">The partial file name, as might be given in one of the configuration files</param> /// <returns>null on error, otherwise the full path</returns> string ImageMapPath(string partialFileName) { // See if the file name cache has been built if (null == imageMapPathCache) { // Construct a cross reference within the cube lights path var path = Path.Combine(cozmoResourcesPath, "assets/compositeImageResources/imageMaps"); imageMapPathCache = FS.BuildNameToRelativePathXref(path); } // look up the file name for the foo return(imageMapPathCache.TryGetValue(partialFileName, out var fullPath) ? fullPath : null); }
/// <summary> /// This scans and builds up the table of animation names /// </summary> void BuildAnimationPaths() { // See if the file name cache has been built if (0 != animationBinPaths.Count) { return; } // Construct a cross reference within the animation bin path var path = Path.Combine(cozmoResourcesPath, "assets/animations"); foreach (var kv in FS.BuildNameToRelativePathXref(path, "bin")) { animationBinPaths[kv.Key] = kv.Value; } // Construct a cross reference within the animation JOSN path, and // append it to the existing cross referenc table path = Path.Combine(cozmoResourcesPath, "config/engine/animations"); foreach (var kv in FS.BuildNameToRelativePathXref(path, "bin")) { animationBinPaths[kv.Key] = kv.Value; } }
/// <summary> /// This scans and builds up the table of independent sprite names /// </summary> /// <remarks> /// This scans the following paths: /// cozmo_resources/assets/sprites/independentSprites /// cozmo_resources/config/sprites/independentSprites /// cozmo_resources/config/facePNGs /// cozmo_resources/config/devOnlySprites/independentSprites /// </remarks> void BuildIndependentSpritePaths() { // See if the file name cache has been built if (null != independentSpritesPathCache) { return; } // Create the cache independentSpritesPathCache = new Dictionary <string, string>(); // Construct a cross reference within the animation groups path // Add in the sprites in reverse order so that the priority items wipe them out for (int idx = config.independentSpritesSearchPaths.Length - 1; idx >= 0; idx--) { // Create the path var path = Path.Combine(cozmoResourcesPath, config.independentSpritesSearchPaths[idx]); // Add in each of the the sprites, possibly wiping out the lower priority ones foreach (var kv in FS.BuildNameToRelativePathXref(path, "png")) { independentSpritesPathCache[kv.Key] = kv.Value; } } }
/// <summary> /// This gets the information about the vision classifiers/detectors /// </summary> void LoadClassifierInfo() { // We'll create a table of each of the classifier/detectors in the // resources. var _classifiers = new Dictionary <string, ClassifierInfo>(); // Scan over the vision config stuff // First a catalog the open CV classifiers var openCVClassifiers = FS.BuildNameToRelativePathXref(Path.Combine(cozmoResourcesPath, visionFolder), "yaml"); // Look up any configuration for those // Start with the Ground plane classifier if (visionConfig.TryGetValue("GroundPlaneClassifier", out var _gp)) { var gp = (Dictionary <string, object>)_gp; // Catch whether or not an item is added bool addedGP = false; // See if there ia file name we can use to match ours if (gp.TryGetValue("FileOrDirName", out var path)) { // See which, of any, files match var name = Path.GetFileNameWithoutExtension((string)path); if (openCVClassifiers.TryGetValue(name, out var cvPath)) { // Update the record with it // Create a classifier info record for it var classifier = new ClassifierInfo( Name: name, Type: "OpenCV", FilePath: "GroundPlaneClassifier", FullPath: cvPath); classifier.Parameters = gp; _classifiers[classifier.Name] = classifier; openCVClassifiers.Remove(name); addedGP = true; } } // If there wasn't a file found, create a dummy entry if (!addedGP) { var classifier = new ClassifierInfo( Name : "GroundPlaneClassifier", Type: "OpenCV", FilePath: (string)path); _classifiers["GroundPlaneClassifier"] = classifier; classifier.Parameters = gp; } } // Transfer the rest of the open CV classifiers to our table foreach (var classifier in openCVClassifiers) { // For now, default the name to be the file name without the extension var name = Path.GetFileNameWithoutExtension(classifier.Key); // Create a classifier info record for it _classifiers[name] = new ClassifierInfo( Name: name, Type: "OpenCV", FilePath: classifier.Key, FullPath: classifier.Value); _classifiers[name].labels = new string[] { "groundPlane" }; } // Load the illumination classifier info if (visionConfig.TryGetValue("IlluminationDetector", out var illd)) { // Set up the structure var illumDetect = (Dictionary <string, object>)illd; illumDetect.TryGetValue("ClassifierConfigPath", out var path); var classifier = new ClassifierInfo( Name: "IlluminationDetector", Type: "LinearClassifier", FilePath: (string)path, FullPath: null != path?Path.Combine(cozmoResourcesPath, (string)path):null); _classifiers["IlluminationDetector"] = classifier; classifier.Parameters = illumDetect; // Read the illumination classifier if (null != classifier.FullPath) { // Get the text for the file var text = File.ReadAllText(classifier.FullPath); // The conversion options classifier.Definition = JSONDeserializer.ToDict(JSONDeserializer.Deserialize <Dictionary <string, object> >(text)); } } // Put in the other classifiers in as well. // Catalog the TFLite classifiers var tfliteFiles = FS.BuildNameToRelativePathXref(Path.Combine(cozmoResourcesPath, visionFolder), "tflite"); if (visionConfig.TryGetValue("NeuralNets", out var NN) && ((Dictionary <string, object>)NN).TryGetValue("Models", out var models)) { // Add each of these models to the internal table; foreach (var _model in (object[])models) { // Convert to the type we can work with var model = (Dictionary <string, object>)_model; // Get some of the basic info model.TryGetValue("modelType", out var modelType); model.TryGetValue("networkName", out var networkName); ClassifierInfo classifier; // Look up the TFLite record in the table if (model.TryGetValue("graphFile", out var graphFile)) { // Convert the graph file name into the name used to look // up the full path var name = Path.GetFileNameWithoutExtension((string)graphFile); tfliteFiles.TryGetValue(name, out var fullPath); // Create the record to hold it classifier = new ClassifierInfo( Name: (string)networkName, Type: (string)modelType, FilePath: (string)graphFile, FullPath: fullPath); // Add in the labels files if (model.TryGetValue("labelsFile", out var labelsFile)) { classifier.LabelsPath = Path.Combine(cozmoResourcesPath, visionFolder, "dnn_models", (string)labelsFile); } // Remove it from the table of TFlite models, so we can add // the rest in later if (null != fullPath) { tfliteFiles.Remove(name); } } else { // This is perhaps an off-board classifier/detector reference // Create the record to hold this classifier = new ClassifierInfo( Name: (string)modelType, Type: (string)networkName); // Is this classifier on a remote server? if ("offboard" == (string)modelType) { // Look up the address of the server for the vision processing Servers?.TryGetValue("offboard_vision", out classifier.serverAddress); } } // Add in the rest of the info and put it in our table of classifiers classifier.Parameters = model; _classifiers[(string)networkName] = classifier; } } // Add in any of the remaining models. // This can include a mobilenet that is not configured, and other hand detectors var mobilenetLabels = Path.Combine(cozmoResourcesPath, visionFolder, "dnn_models", "mobilenet_labels.txt"); if (!File.Exists(mobilenetLabels)) { mobilenetLabels = null; } foreach (var kv in tfliteFiles) { var name = Path.GetFileNameWithoutExtension(kv.Key); var classifier = new ClassifierInfo( Name: name, Type: "TFLite", FilePath: kv.Key, FullPath: kv.Value); // Guess the configuration of the label files if (0 == kv.Key.IndexOf("mobilenet", StringComparison.OrdinalIgnoreCase)) { classifier.LabelsPath = mobilenetLabels; } // And add it to the table _classifiers[name] = classifier; } // And make the classifiers accessible Classifiers = _classifiers; }