'
'
'
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Matrox.MatroxImagingLibrary
Namespace MStr
Friend Class Program
Private Const IMAGE_FILE_DEFINITION As String = MIL.M_IMAGE_PATH & "QcPlates.mim"
Private Const IMAGE_FILE_TO_READ As String = MIL.M_IMAGE_PATH & "LicPlate.mim"
Private Const TEXT_DEFINITION As String = "AVS300CVK781JNK278 EBX380QKN918HCC839 YRH900ZQR756977AMQ GPK742389EYE569ESQ"
Private Const NORMALIZATION_SIZE_Y As Integer = 20
Private Const STRING_MAX_SIZE As Integer = 32
Shared Sub Main(ByVal args() As String)
Dim MilApplication As MIL_ID = MIL.M_NULL
Dim MilSystem As MIL_ID = MIL.M_NULL
Dim MilDisplay As MIL_ID = MIL.M_NULL
Dim MilImage As MIL_ID = MIL.M_NULL
Dim MilOverlayImage As MIL_ID = MIL.M_NULL
Dim MilStrContext As MIL_ID = MIL.M_NULL
Dim MilStrResult As MIL_ID = MIL.M_NULL
Dim NumberOfStringRead As MIL_INT = 0
Dim Score As Double = 0.0
Dim StringResult As New StringBuilder(STRING_MAX_SIZE + 1)
Dim Time As Double = 0.0
Console.Write(Constants.vbLf + "STRING READER MODULE:" + Constants.vbLf)
Console.Write("---------------------" + Constants.vbLf + Constants.vbLf)
MIL.MappAllocDefault(MIL.M_DEFAULT, MilApplication, MilSystem, MilDisplay, CType(MIL.M_NULL, IntPtr), CType(MIL.M_NULL, IntPtr))
MIL.MbufRestore(IMAGE_FILE_DEFINITION, MilSystem, MilImage)
MIL.MdispSelect(MilDisplay, MilImage)
MIL.MdispControl(MilDisplay, MIL.M_OVERLAY, MIL.M_ENABLE)
MIL.MdispInquire(MilDisplay, MIL.M_OVERLAY_ID, MilOverlayImage)
MIL.MstrAlloc(MilSystem, MIL.M_FONT_BASED, MIL.M_DEFAULT, MilStrContext)
MIL.MstrAllocResult(MilSystem, MIL.M_DEFAULT, MilStrResult)
MIL.MstrControl(MilStrContext, MIL.M_CONTEXT, MIL.M_ENCODING, MIL.M_UNICODE)
MIL.MstrControl(MilStrContext, MIL.M_CONTEXT, MIL.M_FONT_ADD, MIL.M_USER_DEFINED)
MIL.MstrEditFont(MilStrContext, MIL.M_FONT_INDEX(0), MIL.M_CHAR_ADD, MIL.M_USER_DEFINED + MIL.M_FOREGROUND_BLACK, MilImage, TEXT_DEFINITION)
MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_GREEN)
MIL.MstrDraw(MIL.M_DEFAULT, MilStrContext, MilOverlayImage, MIL.M_DRAW_CHAR, MIL.M_FONT_INDEX(0), MIL.M_ORIGINAL)
MIL.MstrEditFont(MilStrContext, MIL.M_FONT_INDEX(0), MIL.M_CHAR_NORMALIZE, MIL.M_SIZE_Y, NORMALIZATION_SIZE_Y)
MIL.MstrControl(MilStrContext, MIL.M_CONTEXT, MIL.M_STRING_ADD, MIL.M_USER_DEFINED)
MIL.MstrControl(MilStrContext, MIL.M_CONTEXT, MIL.M_STRING_ADD, MIL.M_USER_DEFINED)
MIL.MstrControl(MilStrContext, MIL.M_CONTEXT, MIL.M_STRING_NUMBER, 1)
MIL.MstrControl(MilStrContext, MIL.M_STRING_INDEX(MIL.M_ALL), MIL.M_STRING_SIZE_MIN, 6)
MIL.MstrControl(MilStrContext, MIL.M_STRING_INDEX(MIL.M_ALL), MIL.M_STRING_SIZE_MAX, 6)
MIL.MstrSetConstraint(MilStrContext, MIL.M_STRING_INDEX(0), MIL.M_DEFAULT, MIL.M_LETTER + MIL.M_UPPERCASE, IntPtr.Zero)
MIL.MstrSetConstraint(MilStrContext, MIL.M_STRING_INDEX(1), MIL.M_DEFAULT, MIL.M_LETTER + MIL.M_UPPERCASE, IntPtr.Zero)
MIL.MstrSetConstraint(MilStrContext, MIL.M_STRING_INDEX(0), 3, MIL.M_DIGIT, IntPtr.Zero)
MIL.MstrSetConstraint(MilStrContext, MIL.M_STRING_INDEX(0), 4, MIL.M_DIGIT, IntPtr.Zero)
MIL.MstrSetConstraint(MilStrContext, MIL.M_STRING_INDEX(0), 5, MIL.M_DIGIT, IntPtr.Zero)
MIL.MstrSetConstraint(MilStrContext, MIL.M_STRING_INDEX(1), 0, MIL.M_DIGIT, IntPtr.Zero)
MIL.MstrSetConstraint(MilStrContext, MIL.M_STRING_INDEX(1), 1, MIL.M_DIGIT, IntPtr.Zero)
MIL.MstrSetConstraint(MilStrContext, MIL.M_STRING_INDEX(1), 2, MIL.M_DIGIT, IntPtr.Zero)
Console.Write("This program has defined a font with this Quebec plates mosaic image." + Constants.vbLf)
Console.Write("Press <Enter> to continue." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MdispControl(MilDisplay, MIL.M_OVERLAY_CLEAR, MIL.M_DEFAULT)
MIL.MbufLoad(IMAGE_FILE_TO_READ, MilImage)
MIL.MstrPreprocess(MilStrContext, MIL.M_DEFAULT)
MIL.MstrRead(MilStrContext, MilImage, MilStrResult)
MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_RESET + MIL.M_SYNCHRONOUS, CType(MIL.M_NULL, IntPtr))
MIL.MstrRead(MilStrContext, MilImage, MilStrResult)
MIL.MappTimer(MIL.M_DEFAULT, MIL.M_TIMER_READ + MIL.M_SYNCHRONOUS, Time)
MIL.MstrGetResult(MilStrResult, MIL.M_GENERAL, MIL.M_STRING_NUMBER + MIL.M_TYPE_MIL_INT, NumberOfStringRead)
If NumberOfStringRead >= 1 Then
Console.Write("The license plate was read successfully ({0:#.##} ms)" + Constants.vbLf + Constants.vbLf, Time * 1000)
MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_BLUE)
MIL.MstrDraw(MIL.M_DEFAULT, MilStrResult, MilOverlayImage, MIL.M_DRAW_STRING, MIL.M_ALL, MIL.M_DEFAULT)
MIL.MgraColor(MIL.M_DEFAULT, MIL.M_COLOR_GREEN)
MIL.MstrDraw(MIL.M_DEFAULT, MilStrResult, MilOverlayImage, MIL.M_DRAW_STRING_BOX, MIL.M_ALL, MIL.M_DEFAULT)
Console.Write(" String Score" + Constants.vbLf)
Console.Write(" -----------------------------------" + Constants.vbLf)
MIL.MstrGetResult(MilStrResult, 0, MIL.M_STRING + MIL.M_TYPE_TEXT_CHAR, StringResult)
MIL.MstrGetResult(MilStrResult, 0, MIL.M_STRING_SCORE, Score)
Console.Write(" {0} {1:0.0}" + Constants.vbLf, StringResult.ToString(), Score)
Else
Console.Write("Error: Plate was not read." + Constants.vbLf)
End If
Console.Write(Constants.vbLf + "Press <Enter> to end." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MstrFree(MilStrContext)
MIL.MstrFree(MilStrResult)
MIL.MbufFree(MilImage)
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL)
End Sub
End Class
End Namespace