/**<summary> Process image or folder of images for debugging a session from device </summary>*/ public void ProcessImages(string path) { ARController arController = FindObjectOfType <ARController>(); if (!arController) { return; } arController.SnapshotPose(); #pragma warning disable 4014 if (path.Contains(".jpg") || path.Contains(".jpeg")) { ServerAPI.LocationFine(locationController.buildingID, FileIO.GetFile(path)); // -> ARController.OnLocationResponse } else { foreach (string file in Directory.GetFiles(path)) { if (file.Contains("jpg") || file.Contains(".jpeg")) { ServerAPI.LocationFine(locationController.buildingID, FileIO.GetFile(file)); } // -> ARController.OnLocationResponse } } #pragma warning restore 4014 }
/**<summary> Called when TextureReader returns image buffer </summary>*/ private async void OnImageCaptured(TextureReaderApi.ImageFormatType format, int width, int height, IntPtr pixelBuffer, int bufferSize) { // Use threads to not block render thread with image handling //TODO ? Do jpg encoding withouth Unity Texture2D which cannot be created in another thread byte[] result = null; byte[] encodedJpg = null; await Task.Run(() => { // 4 bytes per pixel, RGBA byte[] imageBytes = new byte[width * height * 4]; Marshal.Copy(pixelBuffer, imageBytes, 0, imageBytes.Length); // Get pixels and apply transforms // TODO: check if default orientation is device specific Color32[] pixels = ImageUtils.GetPixels(imageBytes); pixels = ImageUtils.Flip(pixels, width, height, true); pixels = ImageUtils.Rotate(pixels, width, height, false); result = ImageUtils.Color32ArrayToByteArray(pixels); }); // Create texture with the image data Texture2D texture = new Texture2D(height, width, TextureFormat.RGBA32, false); texture.LoadRawTextureData(result); await Task.Run(() => { // Get jpg encoded bytedata encodedJpg = texture.EncodeToJPG(80); //File.WriteAllBytes(Application.persistentDataPath.Combine(DateTime.Now.ToString("yyyyMMdd-HHmmss") + ".jpg"), encodedJpg); // For delta offset SnapshotPose(); }); lastLocationTime = Time.time; if (App.config.debug) { Debug.Log("Starting POST request for /location/fine"); } // Send image to LocationAPI await ServerAPI.LocationFine(locationController.buildingID, encodedJpg); // -> OnLocationResponse }