async public Task <QRObject> GetQRCode() { Answer answer = new Answer(); QRObject qrobj = new QRObject(); try { var request = new GeolocationRequest(GeolocationAccuracy.Medium); var location = await Geolocation.GetLocationAsync(request); Geoposition geopos = new Geoposition { Latitude = location.Latitude.ToString(), Long = location.Longitude.ToString() }; answer = await networkservice.GetQRCode(authmanager.GetAuthData(), geopos); if (answer != null && answer.ResData is JObject jData) { qrobj = JsonConvert.DeserializeObject <QRObject>(jData.ToString()); } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); Geoposition geopos = new Geoposition { Latitude = "0.0", Long = "0.0" }; try { answer = await networkservice.GetQRCode(authmanager.GetAuthData(), geopos); if (answer != null && answer.ResData is JObject jData) { qrobj = JsonConvert.DeserializeObject <QRObject>(jData.ToString()); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex); } } return(qrobj); }
/// <summary> /// Set the Tags as Text of the last label created. /// </summary> //public void FinaliseLabel(AnalysisRootObject analysisObject) //{ // if (analysisObject.predictions != null) // { // lastLabelPlacedText = lastLabelPlaced.GetComponent<TextMesh>(); // // Sort the predictions to locate the highest one // List<Prediction> sortedPredictions = new List<Prediction>(); // sortedPredictions = analysisObject.predictions.OrderBy(p => p.probability).ToList(); // Prediction bestPrediction = new Prediction(); // bestPrediction = sortedPredictions[sortedPredictions.Count - 1]; // if (bestPrediction.probability > probabilityThreshold) // { // quadRenderer = quad.GetComponent<Renderer>() as Renderer; // Bounds quadBounds = quadRenderer.bounds; // // Position the label as close as possible to the Bounding Box of the prediction // // At this point it will not consider depth // lastLabelPlaced.transform.parent = quad.transform; // lastLabelPlaced.transform.localPosition = CalculateBoundingBoxPosition(quadBounds, bestPrediction.boundingBox); // // Set the tag text // lastLabelPlacedText.text = bestPrediction.tagName; // // Cast a ray from the user's head to the currently placed label, it should hit the object detected by the Service. // // At that point it will reposition the label where the ray HL sensor collides with the object, // // (using the HL spatial tracking) // Debug.Log("Repositioning Label"); // Vector3 headPosition = Camera.main.transform.position; // RaycastHit objHitInfo; // Vector3 objDirection = lastLabelPlaced.position; // if (Physics.Raycast(headPosition, objDirection, out objHitInfo, 30.0f, SpatialMapping.PhysicsRaycastMask)) // { // lastLabelPlaced.position = objHitInfo.point; // } // } // } // // Reset the color of the cursor // cursor.GetComponent<Renderer>().material.color = Color.green; // // Stop the analysis process // ImageCapture.Instance.ResetImageCapture(); //} public void FinaliseLabel(AnalysisRootObject analysisObject) { if (analysisObject.predictions != null && analysisObject.predictions.ToList().Count != 0) { lastLabelPlacedText = lastLabelPlaced.GetComponent <TextMesh>(); quadRenderer = quad.GetComponent <Renderer>() as Renderer; Bounds quadBounds = quadRenderer.bounds; // Position the label as close as possible to the Bounding Box of the prediction // At this point it will not consider depth QRObject qRObject = new QRObject(); qRObject = (analysisObject.predictions.ToList())[0]; lastLabelPlaced.transform.parent = quad.transform; lastLabelPlaced.transform.localPosition = CalculateBoundingBoxPosition(quadBounds, qRObject.boundingBox); // Set the tag text lastLabelPlacedText.text = qRObject.tagName; // Cast a ray from the user's head to the currently placed label, it should hit the object detected by the Service. // At that point it will reposition the label where the ray HL sensor collides with the object, // (using the HL spatial tracking) Debug.Log("Repositioning Label"); Vector3 headPosition = Camera.main.transform.position; RaycastHit objHitInfo; Vector3 objDirection = lastLabelPlaced.position; if (Physics.Raycast(headPosition, objDirection, out objHitInfo, 30.0f, SpatialMapping.PhysicsRaycastMask)) { lastLabelPlaced.position = objHitInfo.point; } } // Reset the color of the cursor cursor.GetComponent <Renderer>().material.color = Color.green; // Stop the analysis process ImageCapture.Instance.ResetImageCapture(); }
public async Task <string> LoadQRCode() { QRObject qrobj = await qrmanager.GetQRCode(); return(qrobj.Qr); }
/// <summary> /// Call the Computer Vision Service to submit the image. /// </summary> public IEnumerator AnalyseLastImageCaptured(string imagePath, string operation = "label") { Debug.Log("Analyzing..."); WWWForm webForm = new WWWForm(); using (UnityWebRequest unityWebRequest = UnityWebRequest.Post(predictionEndpoint, webForm)) { // Gets a byte array out of the saved image imageBytes = GetImageAsByteArray(imagePath); unityWebRequest.SetRequestHeader("Content-Type", "application/octet-stream"); // The upload handler will help uploading the byte array with the request unityWebRequest.uploadHandler = new UploadHandlerRaw(imageBytes); unityWebRequest.uploadHandler.contentType = "application/octet-stream"; // The download handler will help receiving the analysis from Azure unityWebRequest.downloadHandler = new DownloadHandlerBuffer(); // Send the request yield return(unityWebRequest.SendWebRequest()); string jsonResponse = unityWebRequest.downloadHandler.text; Debug.Log("response: " + jsonResponse); // Create a texture. Texture size does not matter, since // LoadImage will replace with the incoming image size. Texture2D tex = new Texture2D(1, 1); tex.LoadImage(imageBytes); SceneOrganiser.Instance.quadRenderer.material.SetTexture("_MainTex", tex); // The response will be in JSON format, therefore it needs to be deserialized AnalysisRootObject analysisRootObject = new AnalysisRootObject(); analysisRootObject = JsonUtility.FromJson <AnalysisRootObject>(jsonResponse); QRObject qRObject = (analysisRootObject.predictions.ToList())[0]; string data = qRObject.tagName; data = data.Substring(7); switch (operation) { case "label": SceneOrganiser.Instance.FinaliseLabel(analysisRootObject); break; case "get_location": // TODO Validate data, i.e error handling var parameters = data.Split(','); var buid = parameters[0]; var floor_number = int.Parse(parameters[1]); StartCoroutine(navManager.LoadPois(buid, floor_number)); break; case "get_worker": firebaseManager.loadWorker(data); break; default: break; } SceneOrganiser.Instance.FinaliseLabel(analysisRootObject); } }