This project has moved. For the latest updates, please go here.

Example Powershell script for reading OMR forms with the OMR Mark Engine.

Feb 11, 2016 at 8:03 PM
Thought I would share a simple Powershell script that I am using to automate the reading of OMR forms.
<#
.Synopsis
    Parses Optical Mark Recognition information from an image given an OMR Mark Engine template.

.Example

    $OmrResult = Read-OMRMarkEngineImage -Path ScannedFile.tif -TemplatePath Template.mxml
    if ($OmrResult.Validation.IsValid) {
        $OmrResult.DetailsTable | Format-Table
    }

.Example

    $files = ConvertFrom-Csv @'
Path
file1.tif
file2.tif
file3.tif
'@
    $files | Read-OMRMarkEngineImage -TemplatePath Template.mxml

#>
function Read-OMRMarkEngineImage {
    [CmdletBinding()]
    [OutputType([OmrMarkEngine.Output.OmrPageOutput])]
    param (
        [Parameter(Mandatory=$true,
            ValueFromPipeline=$true,
            ValueFromPipelineByPropertyName=$true,
            Position=0)]
        [string[]]$Path,
        [Parameter(Mandatory=$true,
            Position=1)]
        [string]$TemplatePath
    )

    Begin { 
        Add-Type -Path (Join-Path $PSScriptRoot '..\bin\OmrMarkEngine.Core.dll')
    }

    Process {
        foreach ($file in $Path) {
            $engine = New-Object OmrMarkEngine.Core.Engine
            $template = [OmrMarkEngine.Template.OmrTemplate]::Load( $TemplatePath )
            $scannedImage = New-Object -TypeName OmrMarkEngine.Core.Processor.ScannedImage -Argument $file
            $scannedImage.Analyze()
            $output = $engine.ApplyTemplate($template, $scannedImage)
            $output = Add-Member -InputObject $output -PassThru @{
                Validation = $output.Validate($template)
                DetailsTable = @{}
            }
            if ($output.Validation.IsValid ) {
                $output.Details | foreach {
                    $output.DetailsTable.Add($_.Id, ($_.Details | Select -First 1).Value)
                }
            }
            Write-Output $output
            $scannedImage.Dispose()
        }
    }
}
Coordinator
Mar 17, 2016 at 6:29 PM
Thanks for sharing this!