Beispiel #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);
        }
Beispiel #2
0
        public static GenericOcrResponse Map(GoogleOcrResponse ocrResponse)
        {
            var firstResponse = ocrResponse.Responses.FirstOrDefault();
            var firstAnnotation = firstResponse?.Annotations?.FirstOrDefault();
            if (firstAnnotation == null)
                return new GenericOcrResponse();
            var language = firstAnnotation.Locale;
            var summaryText = firstAnnotation.Description;

            return new GenericOcrResponse
            {
                Language = language,
                Detections = firstResponse.Annotations.Select(a => Get(a)).ToList(),
                SummaryText = summaryText
            };
        }