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:
- Initialize the variables
- 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
- First condition is to validate if the current text size, based on its height, is bigger than the maximum boundary (MaximumHeight), if so:
- This is now the new base for our extraction, so set the PlateNumber variable as this current text
- Otherwise, ensure that the current text size is within the 2 boundaries (MinimumHeight & MaximumHeight), if so:
- Append the current text to the end of the PlateNumber variable
- 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:
- Set the BiggestHeight to be as the current height
- 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!