/// <summary> /// ValueType copy from another SessionConfig object into this one. /// </summary> /// <param name="other"></param> public void CopyFrom(NRSessionConfig other) { OptimizedRendering = other.OptimizedRendering; PlaneFindingMode = other.PlaneFindingMode; ImageTrackingMode = other.ImageTrackingMode; TrackingImageDatabase = other.TrackingImageDatabase; }
private static void UpdateDatabaseQuality(NRTrackingImageDatabase database) { lock (m_UpdatedQualityScores) { if (m_UpdatedQualityScores.Count == 0) { return; } for (int i = 0; i < database.Count; ++i) { if (m_UpdatedQualityScores.ContainsKey(database[i].TextureGUID)) { NRTrackingImageDatabaseEntry updatedImage = database[i]; var image_info = m_UpdatedQualityScores[updatedImage.TextureGUID]; updatedImage.Quality = float.Parse(image_info["train_score"].ToString()).ToString("#"); updatedImage.Width = float.Parse(float.Parse(image_info["physical_width"].ToString()).ToString("#")); updatedImage.Height = float.Parse(float.Parse(image_info["physical_height"].ToString()).ToString("#")); database[i] = updatedImage; //Debug.Log("UpdateDatabaseQuality :" + updatedImage.Name); } } m_UpdatedQualityScores.Clear(); // For refreshing inspector UI as new jobs have been enqueued. EditorUtility.SetDirty(database); } // For refreshing inspector UI for updated quality scores. EditorUtility.SetDirty(database); }
private void DeployData(NRTrackingImageDatabase database) { string deploy_path = database.TrackingImageDataOutPutPath; NRDebugger.Log("[TrackingImageDatabase] DeployData to path :" + deploy_path); ZipUtility.UnzipFile(database.RawData, deploy_path, NativeConstants.ZipKey); }
/// <summary> /// ValueType copy from another SessionConfig object into this one. /// </summary> /// <param name="other"></param> public void CopyFrom(NRSessionConfig other) { OptimizedRendering = other.OptimizedRendering; PlaneFindingMode = other.PlaneFindingMode; ImageTrackingMode = other.ImageTrackingMode; TrackingImageDatabase = other.TrackingImageDatabase; EnableNotification = other.EnableNotification; ErrorTipsPrefab = other.ErrorTipsPrefab; }
private static void AddAssetsToNewTrackingImageDatabase() { var selectedImagePaths = new List <string>(); bool unsupportedImagesSelected = false; selectedImagePaths = GetSelectedImagePaths(out unsupportedImagesSelected); if (unsupportedImagesSelected) { var message = string.Format("Some selected images could not be added to the TrackingImageDatabase because " + "they are not in a supported format. Supported image formats are {0}.", k_SupportedImageFormatListMessage); Debug.LogWarningFormat(message); EditorUtility.DisplayDialog("Unsupported Images Selected", message, "Ok"); } if (!Directory.Exists(MarkerDataOutPath)) { NRDebugger.Log("Directory is not exist, create a new one..."); Directory.CreateDirectory(MarkerDataOutPath); } AssetDatabase.Refresh(); string out_path = MarkerDataOutPath + System.Guid.NewGuid().ToString(); if (!Directory.Exists(out_path)) { NRDebugger.Log("Directory is not exist, create a new one..."); Directory.CreateDirectory(out_path); } string binary_path; if (!NRTrackingImageDatabase.FindCliBinaryPath(out binary_path)) { return; } foreach (var item in selectedImagePaths) { string image_path = Application.dataPath.Substring(0, Application.dataPath.Length - 6) + item; s_QualityBackgroundExecutor.PushJob(() => { string param = string.Format("-image_path={0} -save_dir={1} -width={2}", image_path, out_path, 400).Trim(); string result = string.Empty; string error = string.Empty; ShellHelper.RunCommand(binary_path, param, out result, out error); Debug.Log(string.Format("result : {0} error : {1}", result, error)); }); } AssetDatabase.Refresh(); }
public override void OnInspectorGUI() { NRTrackingImageDatabase database = target as NRTrackingImageDatabase; if (database == null) { return; } RunDirtyQualityJobs(database); m_PageIndex = Mathf.Min(m_PageIndex, database.Count / m_PageSize); DrawTitle(); DrawContainer(); DrawColumnNames(); int displayedImageCount = 0; int removeAt = -1; int pageStartIndex = m_PageIndex * m_PageSize; int pageEndIndex = Mathf.Min(database.Count, pageStartIndex + m_PageSize); for (int i = pageStartIndex; i < pageEndIndex; i++, displayedImageCount++) { NRTrackingImageDatabaseEntry updatedImage; bool wasRemoved; DrawImageField(database[i], out updatedImage, out wasRemoved); if (wasRemoved) { removeAt = i; } else if (!database[i].Equals(updatedImage)) { database[i] = updatedImage; } } if (removeAt > -1) { database.RemoveAt(removeAt); } DrawImageSpacers(displayedImageCount); DrawPageField(database.Count); }
private static void RunDirtyQualityJobs(NRTrackingImageDatabase database) { if (database == null) { Debug.Log("database is null"); return; } if (m_DatabaseForQualityJobs != database) { // If another database is already running quality evaluation, // stop all pending jobs to prioritise the current database. if (m_DatabaseForQualityJobs != null) { m_QualityBackgroundExecutor.RemoveAllPendingJobs(); } m_DatabaseForQualityJobs = database; } UpdateDatabaseQuality(database); // Set database dirty to refresh inspector UI for each frame that there are still pending jobs. // Otherwise if there exists one frame with no newly finished jobs, the UI will never get refreshed. // EditorUtility.SetDirty can only be called from main thread. if (m_QualityBackgroundExecutor.PendingJobsCount > 0) { EditorUtility.SetDirty(database); return; } List <NRTrackingImageDatabaseEntry> dirtyEntries = database.GetDirtyQualityEntries(); if (dirtyEntries.Count == 0) { return; } string cliBinaryPath; if (!NRTrackingImageDatabase.FindCliBinaryPath(out cliBinaryPath)) { return; } string outpath = NRTools.GetTrackingImageDataGenPath() + database.GUID + "/"; if (!Directory.Exists(outpath)) { Directory.CreateDirectory(outpath); } var resultjson = database.TrackingImageDataPath + "markers.json"; for (int i = 0; i < dirtyEntries.Count; ++i) { NRTrackingImageDatabaseEntry image = dirtyEntries[i]; var imagePath = AssetDatabase.GetAssetPath(image.Texture); imagePath = Application.dataPath.Substring(0, Application.dataPath.Length - 6) + imagePath; m_QualityBackgroundExecutor.PushJob(() => { BuildImage(cliBinaryPath, image, imagePath, outpath, resultjson); }); } }
public static void BuildDataBase(NRTrackingImageDatabase database) { Debug.Log("Start to build database..."); if (database == null) { Debug.Log("database is null"); return; } List <NRTrackingImageDatabaseEntry> dirtyEntries = database.GetDirtyQualityEntries(); if (dirtyEntries.Count == 0) { return; } string cliBinaryPath; if (!NRTrackingImageDatabase.FindCliBinaryPath(out cliBinaryPath)) { return; } string outpath = NRTools.GetTrackingImageDataGenPath() + database.GUID + "/"; if (!Directory.Exists(outpath)) { Directory.CreateDirectory(outpath); } var resultjson = database.TrackingImageDataPath + "markers.json"; for (int i = 0; i < dirtyEntries.Count; ++i) { NRTrackingImageDatabaseEntry image = dirtyEntries[i]; var imagePath = AssetDatabase.GetAssetPath(image.Texture); BuildImage(cliBinaryPath, image, imagePath, outpath, resultjson); } if (File.Exists(resultjson)) { var json_data = File.ReadAllText(resultjson); var json_obj = JsonMapper.ToObject(json_data); for (int i = 0; i < dirtyEntries.Count; i++) { NRTrackingImageDatabaseEntry image = dirtyEntries[i]; var textureGUID = image.TextureGUID; //Debug.Log("update quality dict " + image.Name); var image_info = json_obj[image.Name]; m_UpdatedQualityScores.Remove(textureGUID); m_UpdatedQualityScores.Add(textureGUID, image_info); } UpdateDatabaseQuality(database); for (int i = 0; i < database.Count; i++) { NRTrackingImageDatabaseEntry image = database[i]; Debug.Log(image.ToString()); } } }