public override void OnInspectorGUI() { AugmentedImageDatabase database = target as AugmentedImageDatabase; if (database == null) { return; } _RunDirtyQualityJobs(database); m_PageIndex = Mathf.Min(m_PageIndex, database.Count / k_PageSize); _DrawTitle(); _DrawContainer(); _DrawColumnNames(); int displayedImageCount = 0; int removeAt = -1; int pageStartIndex = m_PageIndex * k_PageSize; int pageEndIndex = Mathf.Min(database.Count, pageStartIndex + k_PageSize); for (int i = pageStartIndex; i < pageEndIndex; i++, displayedImageCount++) { AugmentedImageDatabaseEntry 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 _UpdateDatabaseQuality(AugmentedImageDatabase database) { lock (s_UpdatedQualityScores) { if (s_UpdatedQualityScores.Count == 0) { return; } for (int i = 0; i < database.Count; ++i) { if (s_UpdatedQualityScores.ContainsKey(database[i].TextureGUID)) { AugmentedImageDatabaseEntry updatedImage = database[i]; updatedImage.Quality = s_UpdatedQualityScores[updatedImage.TextureGUID]; database[i] = updatedImage; } } s_UpdatedQualityScores.Clear(); } // For refreshing inspector UI for updated quality scores. EditorUtility.SetDirty(database); }
/// <summary> /// Loads the images for image recognition /// </summary> protected override async void LoadArAssets() { var characterRepository = Mvx.IoCProvider.Resolve <ICharacterRepository>(); this.characters = await characterRepository.GetAll(); var assets = MainActivity.Instance.Assets; this.imageDatabase = new AugmentedImageDatabase(this.session); foreach (var character in this.characters) { character.Captured = false; using (var streamReader = new StreamReader(assets.Open(character.AssetSticker))) { var image = BitmapFactory.DecodeStream(streamReader.BaseStream); imageDatabase.AddImage(character.Name, image, 0.15f); } } config.AugmentedImageDatabase = this.imageDatabase; session.Configure(config); }
public override void OnInspectorGUI() { AugmentedImageDatabase database = target as AugmentedImageDatabase; if (database == null) { return; } RunDirtyQualityJobs(database); _pageIndex = Mathf.Min(_pageIndex, database.Count / _pageSize); DrawTitle(); DrawContainer(); DrawColumnNames(); // Draw the rows for AugmentedImageDatabaseEntry in the database, // update the database if the entry's image is replaced and // check whether the entry is deleted. int displayedImageCount = 0; int removeAt = -1; int pageStartIndex = _pageIndex * _pageSize; int pageEndIndex = Mathf.Min(database.Count, pageStartIndex + _pageSize); for (int i = pageStartIndex; i < pageEndIndex; i++, displayedImageCount++) { AugmentedImageDatabaseEntry 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); } // Add picked image to the database and ignore the image if duplicate. // It MUST operates after updating the database which also triggers // "ObjectSelectorClosed" and modifies the ObjectPicker object. if (Event.current.commandName == "ObjectSelectorClosed") { Texture2D textureToAdd = EditorGUIUtility.GetObjectPickerObject() as Texture2D; if (textureToAdd != null) { string textureToAddGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(textureToAdd)); bool isDuplicate = false; for (int i = 0; i < database.Count; i++) { if (database[i].TextureGUID.Equals(textureToAddGUID)) { isDuplicate = true; break; } } if (!isDuplicate) { database.Add( new AugmentedImageDatabaseEntry(textureToAdd.name, textureToAdd)); } } } DrawImageSpacers(displayedImageCount); DrawPageField(database.Count); }
private static void RunDirtyQualityJobs(AugmentedImageDatabase database) { if (database == null) { return; } if (_databaseForQualityJobs != database) { // If another database is already running quality evaluation, // stop all pending jobs to prioritise the current database. if (_databaseForQualityJobs != null) { _qualityBackgroundExecutor.RemoveAllPendingJobs(); } _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 (_qualityBackgroundExecutor.PendingJobsCount > 0) { EditorUtility.SetDirty(database); return; } List <AugmentedImageDatabaseEntry> dirtyEntries = database.GetDirtyQualityEntries(); if (dirtyEntries.Count == 0) { return; } string cliBinaryPath; if (!AugmentedImageDatabase.FindCliBinaryPath(out cliBinaryPath)) { return; } for (int i = 0; i < dirtyEntries.Count; ++i) { AugmentedImageDatabaseEntry image = dirtyEntries[i]; var imagePath = AssetDatabase.GetAssetPath(image.Texture); var textureGUID = image.TextureGUID; _qualityBackgroundExecutor.PushJob(() => { string quality; string error; ShellHelper.RunCommand( cliBinaryPath, string.Format("eval-img --input_image_path \"{0}\"", imagePath), out quality, out error); if (!string.IsNullOrEmpty(error)) { Debug.LogError(error); quality = "ERROR"; } lock (_updatedQualityScores) { _updatedQualityScores.Add(textureGUID, quality); } }); } // For refreshing inspector UI as new jobs have been enqueued. EditorUtility.SetDirty(database); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Main); mSurfaceView = FindViewById <GLSurfaceView>(Resource.Id.surfaceview); mDisplayRotationHelper = new DisplayRotationHelper(this); Java.Lang.Exception exception = null; string message = null; try { mSession = new Session(this); } catch (UnavailableArcoreNotInstalledException e) { message = "Please install ARCore"; exception = e; } catch (UnavailableApkTooOldException e) { message = "Please update ARCore"; exception = e; } catch (UnavailableSdkTooOldException e) { message = "Please update this app"; exception = e; } catch (Java.Lang.Exception e) { exception = e; message = "This device does not support AR"; } if (message != null) { Toast.MakeText(this, message, ToastLength.Long).Show(); return; } // Create default config, check is supported, create session from that config. var config = new Google.AR.Core.Config(mSession); if (!mSession.IsSupported(config)) { Toast.MakeText(this, "This device does not support AR", ToastLength.Long).Show(); Finish(); return; } AssetManager assets = this.Assets; var inputStream = assets.Open("receipts.imgdb"); AugmentedImageDatabase imageDatabase = AugmentedImageDatabase.Deserialize(mSession, inputStream); config.SetFocusMode(Config.FocusMode.Auto); config.AugmentedImageDatabase = imageDatabase; mSession.Configure(config); mGestureDetector = new GestureDetector(this, new SimpleTapGestureDetector { SingleTapUpHandler = (MotionEvent arg) => { OnSingleTap(arg); return(true); }, DownHandler = (MotionEvent arg) => true }); mSurfaceView.SetOnTouchListener(this); // Set up renderer. mSurfaceView.PreserveEGLContextOnPause = true; mSurfaceView.SetEGLContextClientVersion(2); mSurfaceView.SetEGLConfigChooser(8, 8, 8, 8, 16, 0); // Alpha used for plane blending. mSurfaceView.SetRenderer(this); mSurfaceView.RenderMode = Rendermode.Continuously; }
/// <summary> /// Inits the image anchors tracking. /// </summary> /// <param name="imageManager">Anchor image manager.</param> public override void InitImageAnchorsTracking(AnchorImageManager imageManager) { arImageDatabase = Resources.Load <AugmentedImageDatabase>("ArCoreImageDatabase"); }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); SetContentView(Resource.Layout.Main); mSurfaceView = FindViewById <GLSurfaceView>(Resource.Id.surfaceview); mDisplayRotationHelper = new DisplayRotationHelper(this); Java.Lang.Exception exception = null; string message = null; try { mSession = new Session(/*context=*/ this); } catch (UnavailableArcoreNotInstalledException e) { message = "Please install ARCore"; exception = e; } catch (UnavailableApkTooOldException e) { message = "Please update ARCore"; exception = e; } catch (UnavailableSdkTooOldException e) { message = "Please update this app"; exception = e; } catch (Java.Lang.Exception e) { exception = e; message = "This device does not support AR"; } if (message != null) { Toast.MakeText(this, message, ToastLength.Long).Show(); return; } // Create default config, check is supported, create session from that config. var config = new Google.AR.Core.Config(mSession); if (!mSession.IsSupported(config)) { Toast.MakeText(this, "This device does not support AR", ToastLength.Long).Show(); Finish(); return; } AugmentedImageDatabase imageDatabase = new AugmentedImageDatabase(mSession); Bitmap bitmap = null; try { var inputStream = Assets.Open("qrcode.png"); bitmap = BitmapFactory.DecodeStream(inputStream); } catch (IOException e) { Log.Error(TAG, "I/O exception loading augmented image bitmap.", e); } index = imageDatabase.AddImage("interstellar", bitmap, 0.01f); config.AugmentedImageDatabase = imageDatabase; mSession.Configure(config); mGestureDetector = new GestureDetector(this, new TapGestureDetector { SingleTapUpHandler = (MotionEvent arg) => { OnSingleTap(arg); return(true); }, DownHandler = (MotionEvent arg) => true }); mSurfaceView.SetOnTouchListener(this); // Set up renderer. mSurfaceView.PreserveEGLContextOnPause = true; mSurfaceView.SetEGLContextClientVersion(2); mSurfaceView.SetEGLConfigChooser(8, 8, 8, 8, 16, 0); // Alpha used for plane blending. mSurfaceView.SetRenderer(this); mSurfaceView.RenderMode = Rendermode.Continuously; }
private void Start() { newDatabase = ScriptableObject.CreateInstance <AugmentedImageDatabase>(); Debug.Log("<DEBUG> SCRIPT STARTED"); }