cancel
Showing results for 
Search instead for 
Did you mean: 
ZePowerDiver

Extract the most predominant text from an image

Background

 

In this article, you will learn the details of how I've managed to extract the most predominant text from an image.

I've recently added a Solution package in the Power Apps Gallery for a sample License Plate Reader.

In the Power Automate flow that uses AI Builder's text recognition that is part of that solution, I have a part that processes the text and extracts only the biggest portion of the results.

Get the know-how by reading on!

 

Resources

YouTube: overview of the solution 

GitHub: solution package to install the app and required resources in your environment.

 

Blog post: the story behind the app and overall solution.

 

The Recipe

At this point, I'll presume you have read the blog post that explains the app and flow and you understand that this section of the flow requires to only extract what is the most predominant section of text in the image.

To do so, the steps are as follow:

  1. Initialize the variables
    • PlateNumber: the string that will contain the final result 2019-12-18_5-03-15.png
    • BiggestHeight: the reference to the largest (highest in height) part of text encountered so far 2019-12-18_5-09-24.png
    • VarianceFactor: since this is OCR there could be potential variance factor in size, so this is the level of acceptable tolerance this can be about 2019-12-18_5-09-42.png
    • MaximumHeight and MaximumHeight: boundaries calculated when a new BiggestHeight is found and based on the VarianceFactor, allows to simplify understanding of the formulas in the flow and not having to reprocess them (calculations) in every loop 2019-12-18_5-10-13.png

       

      2019-12-18_5-09-58.png
  2. Loop through the extraction results. In this case, the JSON that is provided by the AI Builder predict action contains 2 sets of arrays we need to process:
    • results
    • lines 
    • 2019-12-18_5-13-32.png
  3. First condition is to validate if the current text size, based on its height, is bigger than the maximum boundary (MaximumHeight), if so: 

    2019-12-18_5-14-50.png

    • This is now the new base for our extraction, so set the PlateNumber variable as this current text 2019-12-18_5-15-11.png
  4. Otherwise, ensure that the current text size is within the 2 boundaries (MinimumHeight & MaximumHeight), if so: 2019-12-18_5-15-50.png
    • Append the current text to the end of the PlateNumber variable 2019-12-18_5-16-09.png
  5. Once those 2 conditions have been evaluated, before looping back to the next line within the set of results, evaluate a new condition: is the current height bigger then the last set BiggestHeight variable, if so: 2019-12-18_5-16-27.png
    • Set the BiggestHeight to be as the current height 2019-12-18_5-16-45.png
    • Calculate the boundaries (MinimumHeight & MaximumHeight) based on the VarianceFactor using the following formulas:
      • sub(variables('BiggestHeight'),mul(variables('BiggestHeight'),variables('VarianceFactor')))
        add(variables('BiggestHeight'),mul(variables('BiggestHeight'),variables('VarianceFactor')))

Voilà!

This is just another example that even in a low code platform it is possible to perform loops and conditions that allow more complex scenarios to be implemented. Don't hesitate to download the solution from the gallery, edit the flow, adapt it, comment below, etc..

 

Learn and explore

 
The Power Platform really allows business users to resolve business issues quickly while ensuring organizations that the safeguards can be put in place to protect their data and reputation. Make sure to learn and explore the capabilities first in a development/community environment. I hope this article has been useful for you, don't hesitate to share and comment back.
 

About me

 

I'm Éric Sauvé, aka ZePowerDiver, solution architect and team lead at XRM Vision. Recognized as MCT and Business App MVP. I'm a community leader for TDGi's global hackathons in Canada. Power Platform enthusiast, delivering App in a Day sessions, leading local community events such as Montreal Power Platform Happy Hour, actively participating in Montreal Business Application User Group and speaking in Power Platform and Dynamics CE related conferences.
 

You can reach me on:

 

 

Keep on Diving!

 

 

About the Author
  • Experienced Consultant with a demonstrated history of working in the information technology and services industry. Skilled in Office 365, Azure, SharePoint Online, PowerShell, Nintex, K2, SharePoint Designer workflow automation, PowerApps, Microsoft Flow, PowerShell, Active Directory, Operating Systems, Networking, and JavaScript. Strong consulting professional with a Bachelor of Engineering (B.E.) focused in Information Technology from Mumbai University.
  • I am a Microsoft Business Applications MVP and a Senior Manager at EY. I am a technology enthusiast and problem solver. I work/speak/blog/Vlog on Microsoft technology, including Office 365, Power Apps, Power Automate, SharePoint, and Teams Etc. I am helping global clients on Power Platform adoption and empowering them with Power Platform possibilities, capabilities, and easiness. I am a leader of the Houston Power Platform User Group and Power Automate community superuser. I love traveling , exploring new places, and meeting people from different cultures.
  • Read more about me and my achievements at: https://ganeshsanapblogs.wordpress.com/about MCT | SharePoint, Microsoft 365 and Power Platform Consultant | Contributor on SharePoint StackExchange, MSFT Techcommunity
  • Encodian Owner / Founder - Ex Microsoft Consulting Services - Architect / Developer - 20 years in SharePoint - PowerPlatform Fan
  • Founder of SKILLFUL SARDINE, a company focused on productivity and the Power Platform. You can find me on LinkedIn: https://linkedin.com/in/manueltgomes and twitter http://twitter.com/manueltgomes. I also write at https://www.manueltgomes.com, so if you want some Power Automate, SharePoint or Power Apps content I'm your guy 🙂
  • I am the Owner/Principal Architect at Don't Pa..Panic Consulting. I've been working in the information technology industry for over 30 years, and have played key roles in several enterprise SharePoint architectural design review, Intranet deployment, application development, and migration projects. I've been a Microsoft Most Valuable Professional (MVP) 15 consecutive years and am also a Microsoft Certified SharePoint Masters (MCSM) since 2013.
  • Big fan of Power Platform technologies and implemented many solutions.
  • Passionate #Programmer #SharePoint #SPFx #M365 #Power Platform| Microsoft MVP | SharePoint StackOverflow, Github, PnP contributor
  • Web site – https://kamdaryash.wordpress.com Youtube channel - https://www.youtube.com/channel/UCM149rFkLNgerSvgDVeYTZQ/