AWS Logo
Menu

Exploring Amazon Rekognition and Textract in .NET Blazor

Let's learn Amazon Rekognition and Amazon Textract in .NET Blazor

Published Feb 11, 2024

Introduction

Have you ever heard about Amazon Rekognition and Amazon Textract? Please read these pages:
We will explore Amazon Rekognition, which will help us recognize images and analyze videos with machine learning (ML). Amazon Rekognition has the ML models to do their tasks, so we don't have to worry! In addition, we will explore Amazon Textract, which will help us extract printed text, handwriting, etc.

Preparation

Please prepare some of these tools:
  1. Your favorite IDE.
  2. .NET SDK
  3. AWS Account (of course, you will need an AWS Account)
  4. That's all. :)
I use Visual Studio 2022 Community Edition, so feel free to use another IDE.

Creating the Blazor Project

From Visual Studio 2022

  • You may click "Create a new project".
Create project
Create project
  • Search "blazor" and select "Blazor Web App". Click Next.
Blazor Search
Blazor Search
  • Feel free to give any project names and select the project directory. Click Next.
Project Directory
Project Directory
  • I use the default value. Feel free to modify the options. Click Create.
Default
Default

For Visual Studio Code

You may use this command: dotnet new blazorserver -o RekognitionTextractExploration.

Install the Amazon Recognition and Amazon Textract SDK

For Visual Studio

  • Right-click on the Project and click Manage NuGet Packages...
Right click project
Right click project
  • Click Browse, search Rekognition, click AWSSDK.Rekognition, click Install.
Rekognition Install
Rekognition Install
  • Search Textract, and click AWSSDK.Textract, click Install.
Install textract
Install textract

For Visual Studio Code

You may use these commands:
  • dotnet add RekognitionTextractExploration package AWSSDK.Rekognition
  • dotnet add RekognitionTextractExploration package AWSSDK.Textract

Creating a Blazor Page for Amazon Rekognition

  • You can right-click on the Pages directory. You may locate the Pages directory under the Components directory. Select Add > New Item. Click on Razor Component and give any appropriate name, for example, DetectLabels. We will learn to detect labels from a picture which is a feature that Amazon Rekognition has.
  • You may copy-paste this code to DetectLabels.razor.
  • To add the navigation, please add these codes in NavMenu.razor. You may find the file under Components > Layout directory.
  • Your NavMenu.razor will be like this.
Razor result
Razor result

Explanation

There are three important steps. Let's check it out!
  1. The user will upload the file to the server. We will store the file in the temporary directory.
  2. We will read the file as a stream and send that to DetectLabelsAsync.
  3. After getting the result, we will add the detected labels to the results variable.

Short Demo

Creating a Blazor Page for Amazon Textract

  • Create a new Blazor Page for exploring Amazon Textract, for example, Textract.razor.
  • You may copy-paste these codes.
  • To add the navigation, please add these codes in NavMenu.razor.

Explanation

There are three important steps. Let's check it out!
  1. The user will upload the file to the server. We will store the file in the temporary directory.
  2. We will read the file as a stream and send that to DetectDocumentTextAsync.
  3. After getting the result, we will add the detected texts to the results variable.

Demo

What's your opinion?

Those features are cool, right? I only share a feature from each service, you may explore other features as well. If you have any feedback, feel free to share it with me. Please take a look at my repository here.
Thank you
Thank you
Image by katemangostar on Freepik
 

1 Comment