Esempio n. 1
0
        public async Task TestOCRFromRx()
        {
            var apiKey = System.Environment.GetEnvironmentVariable("VISION_API_KEY");

            Assert.IsFalse(string.IsNullOrWhiteSpace(apiKey), "Must provide API Key");

            var imageToText = new ImageToText(apiKey);
            var rxFile      = @"c:\dev\rximage.png";
            var annotated   = @"c:\dev\rximage_annotated.png";
            var ocr         = await imageToText.ProcessImageFileToTextAsync(rxFile);

            using (Stream
                   inStream = new FileStream(rxFile, FileMode.Open, FileAccess.Read),
                   annotatedStream = ImageUtilities.AnnotateImageWithOcrResults(inStream, ocr),
                   outStream = new FileStream(annotated, FileMode.OpenOrCreate, FileAccess.Write))
            {
                await annotatedStream.CopyToAsync(outStream);
            }
        }
        public async Task TestOCRFromRx()
        {
            var apiKey = System.Environment.GetEnvironmentVariable("VISION_API_KEY");
            Assert.IsFalse(string.IsNullOrWhiteSpace(apiKey), "Must provide API Key");

            var imageToText = new ImageToText(apiKey);
            var rxFile = @"c:\dev\rximage.png";
            var annotated = @"c:\dev\rximage_annotated.png";
            var ocr = await imageToText.ProcessImageFileToTextAsync(rxFile);

            using (Stream 
                inStream = new FileStream(rxFile, FileMode.Open, FileAccess.Read),
                annotatedStream = ImageUtilities.AnnotateImageWithOcrResults(inStream, ocr),
                outStream = new FileStream(annotated, FileMode.OpenOrCreate, FileAccess.Write))
            {
                await annotatedStream.CopyToAsync(outStream);
            }
        }