private VisionObject FromPrediction(string fileExtension, Bitmap img, PredictionResult prediction) { var fileInfo = new FileInfo(string.Format(@"C:\Folder\{0}.{1}", Guid.NewGuid(), fileExtension)); var boxImg = GetBoxImage(img, prediction.BoundingBox); var imgBytes = GetImageBytes(boxImg, GetFormat(fileExtension)); var ocr = _ocrService.DoOcr(fileInfo, imgBytes); var result = new VisionObject() { Location = new Rectangle() { X = 0, Y = 0, Width = boxImg.Width, Height = boxImg.Height }, Probability = prediction.Probability, TagName = prediction.TagName, OcrResult = ocr.Data }; return(result); }
private void StackObject(VisionObject obj) { if (objects.Count > 0) { float deltaWidth = (obj.DispRect.Width - dispRect.Width) / 2.0f; if (deltaWidth > 0.0f) { dispRect.Inflate(deltaWidth, 0.0f); } float newX = dispRect.X - (deltaWidth < 0.0f ? deltaWidth : 0.0f); float newY = dispRect.Bottom + PADDING; obj.PutAt(newX, newY); dispRect.Height += obj.DispRect.Height + PADDING; } else { dispRect = obj.DispRect; } objects.Add(obj); }
private void GetHighestConfidence(VisionData data) { float maxConfidence = 0; VisionObject obj = null; if (data != null) { foreach (var vobj in data.objects) { if (vobj.confidence > maxConfidence) { maxConfidence = vobj.confidence; obj = vobj; } } if (obj != null) { int midX = (obj.rectangle.x + obj.rectangle.w) / 2; int midY = (obj.rectangle.y + obj.rectangle.h) / 2; String objString = obj.obj; StartCoroutine(audioManager.playWord(midX, midY, objString)); } } }
private void StackObject(VisionObject obj) { if (objects.Count > 0) { float deltaWidth = (obj.DispRect.Width - dispRect.Width) / 2.0f; if (deltaWidth > 0.0f) dispRect.Inflate(deltaWidth, 0.0f); float newX = dispRect.X - (deltaWidth < 0.0f ? deltaWidth : 0.0f); float newY = dispRect.Bottom + PADDING; obj.PutAt(newX, newY); dispRect.Height += obj.DispRect.Height + PADDING; } else { dispRect = obj.DispRect; } objects.Add(obj); }