'
'
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports Matrox.MatroxImagingLibrary
Namespace MEdge
Friend Class Program
Private Const CONTOUR_IMAGE As String = MIL.M_IMAGE_PATH & "Seals.mim"
Private Const CONTOUR_MAX_RESULTS As Integer = 100
Private Const CONTOUR_MAXIMUM_ELONGATION As Double = 0.8
Private Shared ReadOnly CONTOUR_DRAW_COLOR As Integer = MIL.M_COLOR_GREEN
Private Shared ReadOnly CONTOUR_LABEL_COLOR As Integer = MIL.M_COLOR_RED
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 GraphicList As MIL_ID = MIL.M_NULL
Dim MilEdgeContext As MIL_ID = MIL.M_NULL
Dim MilEdgeResult As MIL_ID = MIL.M_NULL
Dim EdgeDrawColor As Double = CONTOUR_DRAW_COLOR
Dim LabelDrawColor As Double = CONTOUR_LABEL_COLOR
Dim NumEdgeFound As MIL_INT = 0
Dim NumResults As MIL_INT = 0
Dim i As Integer = 0
Dim MeanFeretDiameter(CONTOUR_MAX_RESULTS - 1) As Double
MIL.MappAllocDefault(MIL.M_DEFAULT, MilApplication, MilSystem, MilDisplay, CType(MIL.M_NULL, IntPtr), CType(MIL.M_NULL, IntPtr))
MIL.MbufRestore(CONTOUR_IMAGE, MilSystem, MilImage)
MIL.MdispSelect(MilDisplay, MilImage)
MIL.MgraAllocList(MilSystem, MIL.M_DEFAULT, GraphicList)
MIL.MdispControl(MilDisplay, MIL.M_ASSOCIATED_GRAPHIC_LIST_ID, GraphicList)
Console.Write(Constants.vbLf + "EDGE MODULE:" + Constants.vbLf)
Console.Write("------------" + Constants.vbLf + Constants.vbLf)
Console.Write("This program determines the outer seal diameters in the displayed image " + Constants.vbLf)
Console.Write("by detecting and analyzing contours with the Edge Finder module." + Constants.vbLf)
Console.Write("Press <Enter> to continue." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MedgeAlloc(MilSystem, MIL.M_CONTOUR, MIL.M_DEFAULT, MilEdgeContext)
MIL.MedgeAllocResult(MilSystem, MIL.M_DEFAULT, MilEdgeResult)
MIL.MedgeControl(MilEdgeContext, MIL.M_MOMENT_ELONGATION, MIL.M_ENABLE)
MIL.MedgeControl(MilEdgeContext, MIL.M_FERET_MEAN_DIAMETER + MIL.M_SORT1_DOWN, MIL.M_ENABLE)
MIL.MedgeCalculate(MilEdgeContext, MilImage, MIL.M_NULL, MIL.M_NULL, MIL.M_NULL, MilEdgeResult, MIL.M_DEFAULT)
MIL.MedgeGetResult(MilEdgeResult, MIL.M_DEFAULT, MIL.M_NUMBER_OF_CHAINS + MIL.M_TYPE_MIL_INT, NumEdgeFound)
MIL.MgraColor(MIL.M_DEFAULT, EdgeDrawColor)
MIL.MedgeDraw(MIL.M_DEFAULT, MilEdgeResult, GraphicList, MIL.M_DRAW_EDGES, MIL.M_DEFAULT, MIL.M_DEFAULT)
Console.Write("{0} edges were found in the image." + Constants.vbLf, NumEdgeFound)
Console.Write("Press <Enter> to continue." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MedgeSelect(MilEdgeResult, MIL.M_EXCLUDE, MIL.M_MOMENT_ELONGATION, MIL.M_LESS, CONTOUR_MAXIMUM_ELONGATION, MIL.M_NULL)
MIL.MedgeSelect(MilEdgeResult, MIL.M_EXCLUDE, MIL.M_INCLUDED_EDGES, MIL.M_INSIDE_BOX, MIL.M_NULL, MIL.M_NULL)
MIL.MgraClear(MIL.M_DEFAULT, GraphicList)
MIL.MgraColor(MIL.M_DEFAULT, EdgeDrawColor)
MIL.MedgeDraw(MIL.M_DEFAULT, MilEdgeResult, GraphicList, MIL.M_DRAW_EDGES, MIL.M_DEFAULT, MIL.M_DEFAULT)
Console.Write("Elongated edges and inner edges of each seal were removed." + Constants.vbLf)
Console.Write("Press <Enter> to continue." + Constants.vbLf + Constants.vbLf)
Console.ReadKey()
MIL.MedgeGetResult(MilEdgeResult, MIL.M_DEFAULT, MIL.M_NUMBER_OF_CHAINS + MIL.M_TYPE_MIL_INT, NumResults)
If (NumResults >= 1) AndAlso (NumResults <= CONTOUR_MAX_RESULTS) Then
MIL.MgraColor(MIL.M_DEFAULT, LabelDrawColor)
MIL.MedgeDraw(MIL.M_DEFAULT, MilEdgeResult, GraphicList, MIL.M_DRAW_INDEX, MIL.M_DEFAULT, MIL.M_DEFAULT)
MIL.MedgeGetResult(MilEdgeResult, MIL.M_DEFAULT, MIL.M_FERET_MEAN_DIAMETER, MeanFeretDiameter)
Console.Write("Mean diameter of the {0} outer edges are:" + Constants.vbLf + Constants.vbLf, NumResults)
Console.Write("Index Mean diameter " + Constants.vbLf)
For i = 0 To CType(NumResults - 1, Integer)
Console.Write("{0,-11}{1,-13:0.00}" + Constants.vbLf, i, MeanFeretDiameter(i))
Next i
Else
Console.Write("Edges have not been found or the number of found edges is greater than" + Constants.vbLf)
Console.Write("the specified maximum number of edges !" + Constants.vbLf + Constants.vbLf)
End If
Console.Write(Constants.vbLf + "Press <Enter> to end." + Constants.vbLf)
Console.ReadKey()
MIL.MgraFree(GraphicList)
MIL.MbufFree(MilImage)
MIL.MedgeFree(MilEdgeContext)
MIL.MedgeFree(MilEdgeResult)
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MIL.M_NULL, MIL.M_NULL)
End Sub
End Class
End Namespace