Skip to Main Content

How to Implement SmartZone in .NET with PowerShell

SmartZone powershell

Continuous innovation has allowed Accusoft to build sustained success over the course of three decades. Much of that innovation comes from talented developers creating novel solutions to everyday problems, many of which go on to become patented technologies that provide the company with an edge over competitors. 

Others, however, are the byproduct of looking at problems from a different perspective or using existing technologies in unique ways. Accusoft supports both approaches by hosting special “hackathon” events each year. These events encourage developers to spend time working on their own unique projects or try out ideas they think may have potential but have never been implemented.

For this year’s hackathon, I took a closer look at how our SmartZone SDK could be implemented as part of an automation solution within a .NET environment without creating an entire application from the ground up. What I discovered was that PowerShell modules offer a quick and easy way to deploy character recognition for limited, unique use cases.

.NET and PowerShell

One of the underestimated abilities of the .NET infrastructure is support loading and executing assemblies out of box from the command line using a shell module. Although there are many shell variants available, PowerShell comes preinstalled on most Windows machines and is the only tool required to make the scripts and keep them running. PowerShell also runs on Linux and macOS, which makes it a true cross-platform task automation solution for inventive developers who crave flexibility in their scripting tools. 

Incorporating the best features of other popular shells, PowerShell consists of a command-line shell, a scripting language, and a configuration management framework. One of the unique features of PowerShell, however, is that unlike most shells which can only accept and return text, it can do the same with .NET objects. This means PowerShell modules can be used to build, test, and deploy solutions as well as manage any technology as part of an extensible automation platform.

Implementing SmartZone Character Recognition

Accusoft’s SmartZone technology allows developers to incorporate advanced zonal character recognition to capture both machine-printed and hand-printed data from document fields. It also supports full page optical character recognition (OCR) and allows developers to set confidence values to determine when manual review of recognition results are necessary. 

Implementing those features into an application through a third-party integration is the best way to incorporate recognition capabilities, but there are some use cases where they might need to be used for general tasks outside of a conventional workflow. A number of Accusoft customers, for instance, had inquired about simple ways to use some of SmartZone’s features in their existing process automation software without having to spend weeks of development time integrating those capabilities on a larger scale.

Thanks to the versatility of PowerShell, there’s no reason to build such an application from scratch. SmartZone’s zonal recognition technology can easily be incorporated into any .NET environment with just a few snippets of code. PowerShell syntax itself is not very difficult to understand and for a quick start it should be enough to use a Windows Notepad application, but we recommend using your favorite integrated development environment (IDE) for a better experience.

Getting Started

First, you need to download from the Accusoft SmartZone download page and unpack it to any suitable directory. This bundle contains all required binaries to run SmartZone.

Create a Simple.ps1 file inside the unpacked directory and start typing your script:

using namespace System.Drawing
using namespace System.Reflection
using namespace Accusoft.SmartZoneOCRSdk

# Load assemblies.
Add-Type -AssemblyName System.Drawing
$szPath = Resolve-Path ".\bin\netstandard2.0\Accusoft.SmartZoneOCR.Net.dll"

# Create a SmartZone instance.
$szObj = [SmartZoneOCR]::new()
$szAssetsPath = Resolve-Path ".\bin\assets"
$szObj.OCRDataPath = $szAssetsPath.Path

# Licensing
# $szObj.Licensing.SetSolutionName("Contact Accusoft for getting the license.")
# $szObj.Licensing.SetSolutionKey(+1, 800, 875, 7009)
# $szObj.Licensing.SetOEMLicenseKey("");

# Load test image.
$bitmapPath = Resolve-Path ".\demos\images\OCR\MultiLine.bmp"
[Bitmap] $bitmap = [Image]::FromFile($bitmapPath.Path)

# Recognize the image and print the result.
$result = $szObj.Reader.AnalyzeField([Bitmap] $bitmap);
Write-Host $result.Text

# Free the resources.

This simple code snippet allows you to use SmartZone together with PowerShell in task automation processes like recognizing screenshots, email attachments, and images downloaded by the web browser. It can also be deployed in other similar cases where the advantages of PowerShell modules and cmdlets can help to achieve results faster than writing an application from scratch.

Another Hackathon Success

Identifying a new way to deploy existing Accusoft solutions is one of the reasons why the hackathon event was first created. This script may not reinvent the wheel, but it will help developers save time and money in a lot of situations, which means fewer missed deadlines and faster time to market for software products. Developing unique approaches to existing problems can be difficult with deadlines and coding demands hanging over a developer’s head, so Accusoft’s hackathons are incredibly important for helping the company stay at the forefront of innovation. 

To learn more about how that innovation can help your team implement powerful new features into your applications, talk to one of our solutions experts today!

Ivan Lyapunov

Ivan Lyapunov

Ivan Lyapunov joined Accusoft as a Software Engineer in May of 2016. A graduate of MIREA – Russian Technological University, Ivan received a bachelor’s degree in networking and computer engineering in 2000. As a member of the remote PrizmDoc team, he worked on LibreOffice and Microsoft Office engines for the PrizmDoc server. He currently contributes to the SDK team, where he has been working since 2018. Ivan currently helps the team develop ImagXpress, ScanFix Xpress, FormSuite, SmartZone, and PICTools. In his spare time, Ivan enjoys playing video games with his children, traveling, and experimenting with machine learning algorithms.