private void HandleResult(string json) { var customVisionResult = CustomVisionResult.FromJson(json); //extract bounding boxes var threshold = _predictions = customVisionResult.Predictions.Where(p => p.Probability > _predictionThreshold).ToList(); pictureBox.Refresh(); }
public void ResultReceiver(string msg) { Debug.Log("Received message : " + msg); debugText = msg; try { result = JsonConvert.DeserializeObject <CustomVisionResult>(msg); debugText += "\n message ID " + result.ID; } catch (Exception e) { debugText = "Error " + e.Message; } }
public void ResultReceiver(string msg) { Log("Received message : " + msg); try { result = JsonConvert.DeserializeObject <CustomVisionResult>(msg); Log("message ID " + result.ID); } catch (Exception e) { Log("Error " + e.Message); } }
public async Task <IImageRecognizedResult> DetectImage(Stream imageStream, float threshold) { using (var predictEndpoint = new PredictionEndpoint() { ApiKey = key }) { try { var result = new CustomVisionResult { PredictionResultModel = await predictEndpoint.PredictImageAsync(new Guid(projectId), imageStream) }; var predictedObject = result.PredictionResultModel.Predictions.FirstOrDefault(obj => obj.Probability > threshold); if (predictedObject != null) { result.IsSure = true; } return(result); } catch (Exception e) { Console.WriteLine(e.Message); throw new Exception(); } } //using (var httpClient = new HttpClient()) //{ // httpClient.DefaultRequestHeaders.Add("Prediction-Key", key); // var content = new StreamContent(imageStream); // content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); // var response = await httpClient.PostAsync(uriBase, content); // if (response.IsSuccessStatusCode) // { // string jsonResult = await response.Content.ReadAsStringAsync(); // var result = JsonConvert.DeserializeObject<CustomVisionResult>(jsonResult); // if (result.Predictions.Any() && result.Predictions[0].Probability > threshold) result.IsSure = true; // return result; // } // else // { // throw new Exception(); // } //} }
void Update() { info.SetText(debugText); float dist; float focus = 0.0f; if (startPicture) { gazePoint = gaze.HitInfo.point; if (gazePoint != null) { placeScanner(Camera.main.transform); //if (cursor != null) //{ // Vector3 cameraForward = Camera.main.transform.forward; // cursor.transform.position = gazePoint - 0.1f* cameraForward; // cameraForward.Normalize(); // cursor.transform.rotation = Quaternion.LookRotation(cameraForward, Vector3.up); //} if (gazeStarted == false) { startPoint = gazePoint; dist = Vector3.Distance(Camera.main.transform.position, gazePoint); focus = dist * 0.02f; cursor?.SetActive(true); //enable cursor gazeStarted = true; timer = 0.0f; Log("test gaze started with focus " + focus); } else { // if (Vector3.Distance(startPoint, gazePoint) > focus) // { // // gaze moving away // info.SetText("test gaze reset " + Vector3.Distance(startPoint, gazePoint)); // startPoint = gazePoint; // timer = 0.0f; // // } // else // { timer += Time.deltaTime; // add frame duration if (timer > 1.5f) { Log("test gaze -> take picture "); startPicture = false; // 1 second of gaze at same point gazeStarted = false; cursor?.SetActive(false); TakePicture(); } // } } } else { cursor.SetActive(false); // ScannerScreen.SetActive(false); if (gazeStarted == true) { gazeStarted = false; } } } if (result != null) { try { ScannerScreen.GetComponent <MoveLine>().stopScanAnimation(); ScannerScreen.SetActive(false); // remove the scanner labeler.LabelObjects(result.recognitionData, scanContext.horizontalAngleRadian, scanContext.formFactor, scanContext.origin); Log("Label Set " + result.recognitionData); // + result.ID); } catch (Exception e) { Log("Label error " + e.Message); } //Log("Received message from " + e.Topic + " : " + msg); result = null; } }