// Downlaods each target image IEnumerator TargetDL(string target) { UnityWebRequest www = UnityWebRequestTexture.GetTexture(URL + IDInput + "/" + target); yield return(www.SendWebRequest()); if (www.isDone) { Texture2D texture = ((DownloadHandlerTexture)www.downloadHandler).texture; Debug.Log(texture); texture.name = target; Debug.Log(texture.name); XRDetectionTexture XRDI = new XRDetectionTexture(texture, .15f); SaveImage(XRDI); } www.Dispose(); }
// Save each target image into XRDetectionTexture list public void SaveImage(XRDetectionTexture tex) { Debug.Log("Saving Image"); texHandler = new List <XRDetectionTexture>(); int x = 0; texHandler.Capacity = Targets.Capacity; Debug.Log(texHandler.Capacity); for (x = 0; x < texHandler.Capacity; x++) { texHandler.Insert(x, tex); } if (texHandler.Count == TI.Capacity) { detectionTextures = new List <XRDetectionTexture>(texHandler.Count); int i = 0; for (i = 0; i < detectionTextures.Capacity; i++) { detectionTextures.Add(texHandler[i]); Debug.Log(texHandler[i]); } xr_ = GameObject.FindWithTag("XRController").GetComponent <XRController>(); if (detectionTextures.Count > 0) { Dictionary <string, XRDetectionImage> detectionImages = new Dictionary <string, XRDetectionImage>(); foreach (XRDetectionTexture detectionTexture in detectionTextures) { detectionImages.Add( detectionTexture.tex.name, XRDetectionImage.FromDetectionTexture(detectionTexture)); } xr_.SetDetectionImages(detectionImages); Debug.Log("DetectionImages Count is: " + detectionImages.Count); } } Debug.Log("Saved"); Debug.Log(texHandler[0]); Debug.Log(texHandler[0].tex.name); }
/** * Initializes a new XRDetectionImage from a unity Texture2D and a specified targetWidthInMeters. * The texture must have the "Read/Write Enabled" setting checked, and must have the * "Non Power Of 2" setting set to "None". */ static public XRDetectionImage FromDetectionTexture(XRDetectionTexture texture) { byte[] byteData; if (texture.tex.format == TextureFormat.RGB24) { byteData = texture.tex.GetRawTextureData(); } else { Texture2D newTexture2DInRGB24 = new Texture2D(texture.tex.width, texture.tex.height, TextureFormat.RGB24, false); newTexture2DInRGB24.SetPixels(texture.tex.GetPixels()); newTexture2DInRGB24.Apply(); byteData = newTexture2DInRGB24.GetRawTextureData(); } return(new XRDetectionImage( texture.tex.width, texture.tex.height, texture.widthInMeters, Encoding.RGB24_INVERTED_Y, byteData)); }