You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
using System.Collections;using System.IO;using UnityEngine;using UnityEngine.Networking;publicclassCustomVisionAnalyser:MonoBehaviour{publicstaticCustomVisionAnalyserInstance;privatestringpredictionEndpoint="http://192.168.0.103:5000/upload";privatevoidAwake(){Instance=this;}/// <summary>/// Call the Computer Vision Service to submit the image./// </summary>public IEnumerator AnalyseLastImageCaptured(byte[]imageBytes){WWWFormwebForm=new WWWForm();// 将图片byte数组添加进表单
webForm.AddBinaryData("file", imageBytes,"photo.jpg");// 将图片上传到服务器using(UnityWebRequestunityWebRequest= UnityWebRequest.Post(predictionEndpoint, webForm)){// The download handler will help receiving the analysis from Azure
unityWebRequest.downloadHandler =new DownloadHandlerBuffer();// Send the requestyieldreturn unityWebRequest.SendWebRequest();if(unityWebRequest.isHttpError || unityWebRequest.isNetworkError){
Debug.Log(unityWebRequest.error);}else{stringresponse= unityWebRequest.downloadHandler.text;
Debug.Log(response);}}}}