Пример #1
0
        internal static GoogleOcrResponse FromDynamic(dynamic googleResult)
        {
            GoogleOcrResponse googleOcrResponse = new GoogleOcrResponse();

            googleOcrResponse.Responses = new List <GoogleOcrSingleResponse>();
            foreach (var response in googleResult.responses)
            {
                var singleOcrResponse = new GoogleOcrSingleResponse();
                singleOcrResponse.Annotations = new List <GoogleTextAnnotation>();
                foreach (var textAnnotation in response.textAnnotations)
                {
                    var googleTextAnnotation = new GoogleTextAnnotation();
                    googleTextAnnotation.Description  = textAnnotation.description;
                    googleTextAnnotation.Locale       = textAnnotation.locale;
                    googleTextAnnotation.BoundingPoly = new GoogleBoundingPoly();
                    foreach (var boundingPoly in textAnnotation.boundingPoly)
                    {
                        foreach (var vertice in boundingPoly.Value)
                        {
                            googleTextAnnotation.BoundingPoly.Add(new GoogleVertice {
                                X = vertice.x ?? -1, Y = vertice.y ?? -1
                            });
                        }
                    }
                    singleOcrResponse.Annotations.Add(googleTextAnnotation);
                }
                googleOcrResponse.Responses.Add(singleOcrResponse);
            }
            return(googleOcrResponse);
        }
Пример #2
0
 private static GenericBoxDetection Get(GoogleTextAnnotation a)
 {
     return(new GenericBoxDetection
     {
         DetectedText = a.Description,
         BoundingBox = new GenericBoundingBox {
             Height = 0, Left = 0, Top = 0, Width = 0
         }
     });
 }
Пример #3
0
        private static GenericBoxDetection Get(GoogleTextAnnotation a)
        {
            var leftest = a.BoundingPoly.OrderBy(e => e.X).ToList();
            var upperLeftCorner = leftest[1];
            var height = leftest[0].Y - upperLeftCorner.Y;
            if (leftest[0].Y < leftest[1].Y) {
                upperLeftCorner = leftest[0];
                height = leftest[1].Y - upperLeftCorner.Y;
            }

            var rightMostCorner = leftest.Last();
            var widht = rightMostCorner.X - upperLeftCorner.X;
            return new GenericBoxDetection
            {
                DetectedText = a.Description,
                BoundingBox = new GenericBoundingBox 
                {
                    Left = upperLeftCorner.X,
                    Top = upperLeftCorner.Y,
                    Height = height,
                    Width = widht
                }
            };
        }