public async static void GetTextFromS3(IAmazonTextract textractClient, string bucketName, string keyName) { List <Block> result = null; DetectDocumentTextRequest detectTextRequest = new DetectDocumentTextRequest() { Document = new Document { S3Object = new S3Object { Bucket = bucketName, Name = keyName } } }; try { Task <DetectDocumentTextResponse> detectTask = textractClient.DetectDocumentTextAsync(detectTextRequest); DetectDocumentTextResponse detectTextResponse = await detectTask; result = detectTextResponse.Blocks; //PrintBlockDetails(result); } catch (AmazonTextractException textractException) { Console.WriteLine(textractException.Message, textractException.InnerException); } }
public async Task <List <Block> > GetTextFromStream(IAmazonTextract textractClient, MemoryStream stream) { List <Block> result = null; DetectDocumentTextRequest detectTextRequest = new DetectDocumentTextRequest() { Document = new Document { Bytes = stream } }; try { Task <DetectDocumentTextResponse> detectTask = textractClient.DetectDocumentTextAsync(detectTextRequest); DetectDocumentTextResponse detectTextResponse = await detectTask; result = detectTextResponse.Blocks; //PrintBlockDetails(result); } catch (AmazonTextractException textractException) { Console.WriteLine(textractException.Message, textractException.InnerException); } return(result); }
public IActionResult Post() { AmazonTextractClient objTextExtract = new AmazonTextractClient("AKIA23XZGIB6BEUBA5HM", "ePmW8ZsldWdQP3hmillAOMLu+A5b4ePgeBV3+/O5", Amazon.RegionEndpoint.USEast1); DetectDocumentTextRequest request = new DetectDocumentTextRequest(); byte[] fileData = null; using (var ms = new MemoryStream()) { HttpContext.Request.Form.Files[0].CopyTo(ms); fileData = ms.ToArray(); string s = Convert.ToBase64String(fileData); // act on the Base64 data } request.Document = new Document { Bytes = new MemoryStream(fileData) }; var task = UploadImageForRekognition(objTextExtract, request); task.Wait(); var result = task.Result; return(Ok(result)); }
/// <summary> /// Detects text in the input document. Amazon Textract can detect lines of text and the /// words that make up a line of text. The input document must be an image in JPG or PNG /// format. <code>DetectDocumentText</code> returns the detected text in an array of <a>Block</a> /// objects. /// /// /// <para> /// Each document page has as an associated <code>Block</code> of type PAGE. Each PAGE /// <code>Block</code> object is the parent of LINE <code>Block</code> objects that represent /// the lines of detected text on a page. A LINE <code>Block</code> object is a parent /// for each word that makes up the line. Words are represented by <code>Block</code> /// objects of type WORD. /// </para> /// /// <para> /// <code>DetectDocumentText</code> is a synchronous operation. To analyze documents /// asynchronously, use <a>StartDocumentTextDetection</a>. /// </para> /// /// <para> /// For more information, see <a href="https://docs.aws.amazon.com/textract/latest/dg/how-it-works-detecting.html">Document /// Text Detection</a>. /// </para> /// </summary> /// <param name="request">Container for the necessary parameters to execute the DetectDocumentText service method.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// /// <returns>The response from the DetectDocumentText service method, as returned by Textract.</returns> /// <exception cref="Amazon.Textract.Model.AccessDeniedException"> /// You aren't authorized to perform the action. /// </exception> /// <exception cref="Amazon.Textract.Model.BadDocumentException"> /// Amazon Textract isn't able to read the document. /// </exception> /// <exception cref="Amazon.Textract.Model.DocumentTooLargeException"> /// The document can't be processed because it's too large. The maximum document size /// for synchronous operations 5 MB. The maximum document size for asynchronous operations /// is 500 MB for PDF format files. /// </exception> /// <exception cref="Amazon.Textract.Model.InternalServerErrorException"> /// Amazon Textract experienced a service issue. Try your call again. /// </exception> /// <exception cref="Amazon.Textract.Model.InvalidParameterException"> /// An input parameter violated a constraint. For example, in synchronous operations, /// an <code>InvalidParameterException</code> exception occurs when neither of the <code>S3Object</code> /// or <code>Bytes</code> values are supplied in the <code>Document</code> request parameter. /// Validate your parameter before calling the API operation again. /// </exception> /// <exception cref="Amazon.Textract.Model.InvalidS3ObjectException"> /// Amazon Textract is unable to access the S3 object that's specified in the request. /// </exception> /// <exception cref="Amazon.Textract.Model.ProvisionedThroughputExceededException"> /// The number of requests exceeded your throughput limit. If you want to increase this /// limit, contact Amazon Textract. /// </exception> /// <exception cref="Amazon.Textract.Model.ThrottlingException"> /// Amazon Textract is temporarily unable to process the request. Try your call again. /// </exception> /// <exception cref="Amazon.Textract.Model.UnsupportedDocumentException"> /// The format of the input document isn't supported. Amazon Textract supports documents /// that are .png or .jpg format. /// </exception> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/textract-2018-06-27/DetectDocumentText">REST API Reference for DetectDocumentText Operation</seealso> public virtual Task <DetectDocumentTextResponse> DetectDocumentTextAsync(DetectDocumentTextRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var options = new InvokeOptions(); options.RequestMarshaller = DetectDocumentTextRequestMarshaller.Instance; options.ResponseUnmarshaller = DetectDocumentTextResponseUnmarshaller.Instance; return(InvokeAsync <DetectDocumentTextResponse>(request, options, cancellationToken)); }
internal virtual DetectDocumentTextResponse DetectDocumentText(DetectDocumentTextRequest request) { var options = new InvokeOptions(); options.RequestMarshaller = DetectDocumentTextRequestMarshaller.Instance; options.ResponseUnmarshaller = DetectDocumentTextResponseUnmarshaller.Instance; return(Invoke <DetectDocumentTextResponse>(request, options)); }
public async Task <DetectDocumentTextResponse> DetectTextS3(string bucketName, string key) { var result = new DetectDocumentTextResponse(); var s3Object = new S3Object { Bucket = bucketName, Name = key }; var request = new DetectDocumentTextRequest(); request.Document = new Document { S3Object = s3Object }; return(await this.textract.DetectDocumentTextAsync(request)); }
public async Task <DetectDocumentTextResponse> DetectTextLocal(string localPath) { var result = new DetectDocumentTextResponse(); if (File.Exists(localPath)) { var request = new DetectDocumentTextRequest(); request.Document = new Document { Bytes = new MemoryStream(File.ReadAllBytes(localPath)) }; return(await this.textract.DetectDocumentTextAsync(request)); } Console.WriteLine("File: " + localPath + " doesn't exist"); return(result); }
public override async Task RunCommand(object sender) { var engine = (IAutomationEngineInstance)sender; var vAccessKey = (string)await v_AccessKey.EvaluateCode(engine); var vSecretKey = (string)await v_SecretKey.EvaluateCode(engine); var ocrRequest = new DetectDocumentTextRequest(); MemoryStream memStream = new MemoryStream(); if (v_ImageType == "Filepath") { string vFilePath = (string)await v_FilePath.EvaluateCode(engine); FileStream image = File.OpenRead(vFilePath); image.CopyTo(memStream); } else { Bitmap vBitmap = (Bitmap)await v_Bitmap.EvaluateCode(engine); vBitmap.Save(memStream, ImageFormat.Jpeg); } ocrRequest.Document = new Document(); ocrRequest.Document.Bytes = memStream; AmazonTextractConfig config = new AmazonTextractConfig(); config.RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(v_AWSRegion); AmazonTextractClient client = new AmazonTextractClient(vAccessKey, vSecretKey, config); DetectDocumentTextResponse results = client.DetectDocumentText(ocrRequest); string readText = ""; if (results.HttpStatusCode == System.Net.HttpStatusCode.OK) { foreach (Block block in results.Blocks) { if (block.BlockType.Value == "LINE") { readText += block.Text + "\n"; } } } else { throw new Exception("Call to AWS textract failed"); } readText.SetVariableValue(engine, v_OutputUserVariableName); }
private static async Task <string> ReadText(string textUrl) { using var client = new AmazonTextractClient(); var document = new Document { S3Object = new Amazon.Textract.Model.S3Object { Bucket = S3BucketName, Name = textUrl } }; var request = new DetectDocumentTextRequest { Document = document }; var response = await client.DetectDocumentTextAsync(request); return(GetTextFromBlocks(response.Blocks)); }
private async Task <DetectDocumentTextResponse> UploadImageForRekognition(AmazonTextractClient objRekClient, DetectDocumentTextRequest objDetectText) { return(await objRekClient.DetectDocumentTextAsync(objDetectText)); }