'
'
'
'
'
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Runtime.InteropServices
Imports Matrox.MatroxImagingLibrary
Namespace MDigProcess
Friend Class Program
Private Const BUFFERING_SIZE_MAX As Integer = 20
Public Class HookDataStruct
Public MilDigitizer As MIL_ID
Public MilImageDisp As MIL_ID
Public ProcessedImageCount As Integer
End Class
Shared Sub Main(ByVal args() As String)
Dim MilApplication As MIL_ID = MIL.M_NULL
Dim MilSystem As MIL_ID = MIL.M_NULL
Dim MilDigitizer As MIL_ID = MIL.M_NULL
Dim MilDisplay As MIL_ID = MIL.M_NULL
Dim MilImageDisp As MIL_ID = MIL.M_NULL
Dim MilGrabBufferList(BUFFERING_SIZE_MAX - 1) As MIL_ID
Dim MilGrabBufferListSize As Integer = 0
Dim ProcessFrameCount As MIL_INT = 0
Dim ProcessFrameRate As Double = 0
Dim UserHookData As New HookDataStruct()
MIL.MappAllocDefault(MIL.M_DEFAULT, MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImageDisp)
MIL.MappControl(MIL.M_ERROR, MIL.M_PRINT_DISABLE)
For MilGrabBufferListSize = 0 To BUFFERING_SIZE_MAX - 1
MIL.MbufAlloc2d(MilSystem, MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_X, MIL.M_NULL), MIL.MdigInquire(MilDigitizer, MIL.M_SIZE_Y, MIL.M_NULL), 8 + MIL.M_UNSIGNED, MIL.M_IMAGE + MIL.M_GRAB + MIL.M_PROC, MilGrabBufferList(MilGrabBufferListSize))
If MilGrabBufferList(MilGrabBufferListSize) <> MIL.M_NULL Then
MIL.MbufClear(MilGrabBufferList(MilGrabBufferListSize), &HFF)
Else
Exit For
End If
Next MilGrabBufferListSize
MIL.MappControl(MIL.M_ERROR, MIL.M_PRINT_ENABLE)
Dim n As Integer = 0
Do While n < 2 AndAlso MilGrabBufferListSize > 0
MilGrabBufferListSize -= 1
MIL.MbufFree(MilGrabBufferList(MilGrabBufferListSize))
n += 1
Loop
Console.WriteLine()
Console.WriteLine("MULTIPLE BUFFERED PROCESSING.")
Console.WriteLine("-----------------------------")
Console.WriteLine()
Console.Write("Press <Enter> to start processing." + Constants.vbCr)
MIL.MdigGrabContinuous(MilDigitizer, MilImageDisp)
Console.ReadKey()
MIL.MdigHalt(MilDigitizer)
UserHookData.MilDigitizer = MilDigitizer
UserHookData.MilImageDisp = MilImageDisp
UserHookData.ProcessedImageCount = 0
Dim hUserData As GCHandle = GCHandle.Alloc(UserHookData)
Dim ProcessingFunctionPtr As New MIL_DIG_HOOK_FUNCTION_PTR(AddressOf ProcessingFunction)
MIL.MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize, MIL.M_START, MIL.M_DEFAULT, ProcessingFunctionPtr, CType(hUserData, IntPtr))
Console.WriteLine("Press <Enter> to stop. ")
Console.WriteLine()
Console.ReadKey()
MIL.MdigProcess(MilDigitizer, MilGrabBufferList, MilGrabBufferListSize, MIL.M_STOP, MIL.M_DEFAULT, ProcessingFunctionPtr, CType(hUserData, IntPtr))
hUserData.Free()
MIL.MdigInquire(MilDigitizer, MIL.M_PROCESS_FRAME_COUNT, ProcessFrameCount)
MIL.MdigInquire(MilDigitizer, MIL.M_PROCESS_FRAME_RATE, ProcessFrameRate)
Console.WriteLine()
Console.WriteLine()
Console.WriteLine("{0} frames grabbed at {1:0.0} frames/sec ({2:0.0} ms/frame).", ProcessFrameCount, ProcessFrameRate, 1000.0 / ProcessFrameRate)
Console.WriteLine("Press <Enter> to end.")
Console.WriteLine()
Console.ReadKey()
Do While MilGrabBufferListSize > 0
MilGrabBufferListSize -= 1
MIL.MbufFree(MilGrabBufferList(MilGrabBufferListSize))
Loop
MIL.MappFreeDefault(MilApplication, MilSystem, MilDisplay, MilDigitizer, MilImageDisp)
End Sub
Private Const STRING_LENGTH_MAX As Integer = 20
Private Const STRING_POS_X As Integer = 20
Private Const STRING_POS_Y As Integer = 20
Private Shared Function ProcessingFunction(ByVal HookType As MIL_INT, ByVal HookId As MIL_ID, ByVal HookDataPtr As IntPtr) As MIL_INT
Dim ModifiedBufferId As MIL_ID = MIL.M_NULL
If (Not IntPtr.Zero.Equals(HookDataPtr)) Then
Dim hUserData As GCHandle = CType(HookDataPtr, GCHandle)
Dim UserData As HookDataStruct = CType(hUserData.Target, HookDataStruct)
MIL.MdigGetHookInfo(HookId, MIL.M_MODIFIED_BUFFER + MIL.M_BUFFER_ID, ModifiedBufferId)
UserData.ProcessedImageCount += 1
Console.Write("Processing frame #{0}." & Constants.vbCr, UserData.ProcessedImageCount)
MIL.MgraText(MIL.M_DEFAULT, ModifiedBufferId, STRING_POS_X, STRING_POS_Y, String.Format("{0}", UserData.ProcessedImageCount))
MIL.MimArith(ModifiedBufferId, MIL.M_NULL, UserData.MilImageDisp, MIL.M_NOT)
End If
Return 0
End Function
End Class
End Namespace