//private TestScript testScript; internal void ResetProcessing() { debug.PrintPlus("in reset processing"); this._imageCapture.ResetProcessing(); this._imageProcessor.ResetProcessing(); this._dbpediaResult = null; this._processing = false; }
public void ResetProcessing() { this._sourceImage = null; this._webDetection = null; this._dbpediaResult = null; this._beginProcessingTime = 0.0f; this._endProcessingTime = 0.0f; this.output = null; //this.annotateImageResponses = null; this._completed = false; this._processing = false; }
// Update is called once per frame void Update() { if (this._processing) { return; } if ((this._imageProcessor.output != null) && (this._imageProcessor._processing == true) && (this._imageProcessor._completed == true)) { //we have some output to process this._processing = true; this._dbpediaResult = this._imageProcessor.output; //this.TestScriptDisplay(); StartCoroutine(CreateDisplay()); } }
IEnumerator RunDBPediaQueries() { DBpediaResult db = new DBpediaResult(); foreach (WebEntity e in this._webDetection.webEntities) { string desc = e.description; string query = GetDBpediaQueryString(desc); using (UnityWebRequest req = UnityWebRequest.Get(query)) { //request and wait for the desired page yield return(req.SendWebRequest()); if (req.isNetworkError) { Debug.Log("Web request error: " + req.error); } else { db = ProcessDBpediaJSON(req.downloadHandler.text); if (db.Success) { break; } } } } if (db.Success) { //we successfully resolved the image this._dbpediaResult = db; } else { //we failed to resolve the image this._dbpediaResult = null; } }
//private void PrintDebugMessage(string msg) //{ // this.debugMessage.text = msg; //} IEnumerator BeginProcessing() { this.debug.Print("in beginprocessing"); //timestamp the beginning of the processing cycle this._beginProcessingTime = Time.time; //we have the source image. //we need to create a request and invoke the machine vision service //convert the source image into a base64-encoded string byte[] jpg = this._sourceImage.EncodeToJPG(); string base64 = System.Convert.ToBase64String(jpg); //create the request collection object AnnotateImageRequests requests = new AnnotateImageRequests(); requests.requests = new List <AnnotateImageRequest>(); //create the request object AnnotateImageRequest request = new AnnotateImageRequest(); //configure the request object request.image = new Image(); request.image.content = base64; request.features = new List <Feature>(); Feature feature = new Feature(); //we are only interested in web detections feature.type = FeatureType.WEB_DETECTION.ToString(); //we only want a single response feature.maxResults = this.maxResults; request.features.Add(feature); requests.requests.Add(request); //creat a MachineVisionClient to post the request MachineVisionClient client = new MachineVisionClient(); //send the request yield return(client.SendWebRequest(requests)); //the MachineVisionClient will send the request and create response object //get a reference to the response object MachineVisionResponse res = client.response; //check if an error was encountered during the request if (res.isError) { //an error occurred during processing Debug.Log("Web detection object is null."); //return a null web detection object this._webDetection = null; //set the DPpedia result to null this.output = new DBpediaResult(); yield break; } //if we get here, then we have successully returned a web detection from the Google Vision API this._webDetection = res.annotateImageResponse.webDetection; //now run the dbpedia queries yield return(StartCoroutine(RunDBPediaQueries())); if (this._dbpediaResult == null) { //the retrieval of results from dbpedia failed, so create a null dbpedia result this.output = new DBpediaResult(); } else { this.output = this._dbpediaResult; } //if we get here then we have a result to process //timestamp the end processing time this._endProcessingTime = Time.time; //mark the processing as completed this._completed = true; this.debug.Print("db-result: " + this._dbpediaResult.Success.ToString()); }