PDA

View Full Version : COM events in FindObject Sample



Teresa
November 23, 2007, 18:46:58
Hello,

I'm trying understand how to get the MV Motion Direction results, through the associated COM event MV_ALGORITHM_START_EVENT, so i followed the VB6 FindObject sample but i didnt understand the following issues:

1- When/Where are the MV Blob Counter events enabled?

According to help documentation this should be done with the IMVFilterEvents::Enable method, so i thought in something like:

"Dim enableEvents As IMVSCFilterEvents
Dim MotionCookie As Long
'Activar Eventos do MV Motion Detection Filter:
MotionCookie = enableEvents.Enable("MV Motion Direction")
"
is it necessary?

2- At the _IMVSmartControlEvents::FilterEvent method the BlobCookie variable is compared with the returned cookie value, but when/where was BlobCookie initialized? I mean, how do i set that variable to identify the events from the MV Motion DeteDirectionction filter?
I thought in something like:
Private Sub MVSmartControlOriginal_FilterEvent(ByVal Cookie As Long, ByVal EventCode As Long)

"
'If Cookie = ??? Then
Dim Motion As Boolean
Dim MotionDetected As IMVMotionDirection
Dim TextOverlay As IMVTextOverlay
Dim graph As IMVSCFilterGraph
Dim text As String

Set graph = MVSmartControlOriginal.Object
Set MotionDetected = graph.GetFilter("MV Motion Direction")
Set TextOverlay = graph.GetFilter("MV Text Overlay")

Motion = MotionDetected.GetMotion

TextOverlay.text = Motion
'error:
'End If

End Sub"


Thank you in advance.

Teresa

Marc Cymontkowski
November 23, 2007, 20:36:34
Hi Teresa,

Your theory is absolutely right. Enable("MV Motion Detection") returns the Cookie for the motion detection filter, which you use in the filter event handler to see if the event was called by the motion detection filter.

In the VB6 sample we disabled this since VB6 and threading is a bit critical, but we forgot to remove the event.

Meanwhile we implemented it in a way that filter events do actually work in Vb6. If you are using Version 3.1 of the development kit, you can contact me through support@montivision.com to get an updated Smart Control.


Best Regards,

Marc Cymontkowski

Teresa
November 26, 2007, 11:38:15
Hi Marc,

I don't know if I'm having a threading problem but, I receive an error when enabling the filter events with the IMVFilterEvents::Enable method.
In the following code I would just like to set a checkBox value to TRUE when I receive an event from the MV Motion Direction filter but it generates an error:
"Run-time error '91': Object variable or With variable not set"

Code:

Private Sub MVSmartControl_FilterEvent(ByVal Cookie As Long, ByVal EventCode As Long)

If Cookie = MotionCookie Then
'On Error GoTo error
chkMStart.Value = 1
End If

error:
End If
End Sub

Private Sub MVSmartControl_OnFilterCreatedVB(ByVal Label As String)
If Label = "MV Motion Direction" Then
Dim enableEvents As IMVSCFilterEvents
MotionCookie = enableEvents.Enable("MV Motion Direction") 'ERROR!!!!
End If
End Sub

I can I fix this error?
Thank you in advance.

Best regards,

Teresa

Teresa
November 26, 2007, 15:15:32
Hello,

:)That error occurs because the expression: MotionCookie = enableEvents.Enable("MV Motion Direction"), returns "Nothing".

If I set the MotionCookie variable after the form is activated, the problem is resolved, and makes sense!

:confused: Although, when I run the application it freeze, and nothing happen!
Now, my code is as simple as:


Dim MotionCookie As Long


Private Sub UnloadConfig()
On Error Resume Next
Dim graph As IMVSCFilterGraph
Dim FilterEvents As IMVSCFilterEvents

Set graph = MVSmartControl.Object
Set FilterEvents = MVSmartControl.Object

FilterEvents.Disable "MV Motion Detection"

MVIOLed.Init "", Null

graph.Stop

MVFilterPropertyControl.ReleasePages

graph.UnloadConfig

error:
End Sub

Private Sub LoadConfig()
On Error GoTo error:
Dim graph As IMVSCFilterGraph
Dim videoWindow As IMVSCVideoWindow


Set graph = MVSmartControl.Object
Set videoWindow = MVSmartControl.Object


UnloadConfig

graph.LoadConfig App.Path + "\Axis_MotionDetection_Rec.mvp"

MotionCookie = FilterEvents.Enable("MV Motion Detection")

MVIOLed.Init "MV I/O Renderer", MVSmartControl.Object

'videoWindowOrig.RendererFilter = "Video Renderer"
'videoWindow.SetVideoRenderer graph.FilterGraphManager, "Video Renderer"

MVFilterPropertyControl.Init "MV Motion Detection", MVSmartControl.Object, 7
MVFilterPropertyControl.CurrentPage = 0


graph.Start

error:
End Sub


Private Sub Form_Activate()
LoadConfig
End Sub

Private Sub Form_Deactivate()
UnloadConfig
End Sub

Private Sub Form_Unload(Cancel As Integer)
On Error GoTo error
UnloadConfig

error:
End Sub

Private Sub MVSmartControlOriginal_FilterEvent(ByVal Cookie As Long, ByVal EventCode As Long)

If Cookie = MotionCookie Then
On Error GoTo error
Dim Motion As Long
Dim Text As String
Dim MotionDetected As IMVMotionDetection
Dim graph As IMVSCFilterGraph

Set graph = MVSmartControl.Object
Set MotionDetected = graph.GetFilter("MV Motion Detection")


Motion = MotionDetected.IsMotionDetected
If Motion Then
Text = "Motion Detected"
Else
Text = ""
End If
txtMotion.Text = Text

error:
End If
End Sub

I dont understand why this code doesn't work.
Can anyone help me please?

Best regards,

Teresa

Teresa
November 26, 2007, 17:18:55
Im sorry, my mistake again :(.
The code works perfectly fine:



Dim MotionCookie As Long

Private Sub UnloadConfig()
On Error Resume Next
Dim graph As IMVSCFilterGraph
Dim FilterEvents As IMVSCFilterEvents

Set graph = MVSmartControl.Object
Set FilterEvents = MVSmartControl.Object

FilterEvents.Disable "MV Motion Detection"

MVIOLed.Init "", Null

graph.Stop

MVFilterPropertyControl.ReleasePages

graph.UnloadConfig

error:
End Sub

Private Sub LoadConfig()


On Error GoTo error:
Dim graph As IMVSCFilterGraph
Dim videoWindow As IMVSCVideoWindow
Dim FilterEvents As IMVSCFilterEvents


Set graph = MVSmartControl.Object
Set videoWindow = MVSmartControl.Object
Set FilterEvents = MVSmartControl.Object

UnloadConfig

graph.LoadConfig App.Path + "\Axis_MotionDetection_Rec.mvp"



MVIOLed.Init "MV I/O Renderer", MVSmartControl.Object

'videoWindowOrig.RendererFilter = "Video Renderer"
'videoWindow.SetVideoRenderer graph.FilterGraphManager, "Video Renderer"

MVFilterPropertyControl.Init "MV Motion Detection", MVSmartControl.Object, 7
MVFilterPropertyControl.CurrentPage = 0

MotionCookie = FilterEvents.Enable("MV Motion Detection")
graph.Start

error:
End Sub

Private Sub Form_Activate()
LoadConfig
End Sub

Private Sub Form_Deactivate()
UnloadConfig
End Sub

Private Sub Form_Unload(Cancel As Integer)
On Error GoTo error
UnloadConfig

error:
End Sub

Private Sub MVSmartControl_FilterEvent(ByVal Cookie As Long, ByVal EventCode As Long)

If Cookie = MotionCookie Then
On Error GoTo error
Dim graph As IMVSCFilterGraph
Dim Text As String

Set graph = MVSmartControl.Object
Set MotionDetected = graph.GetFilter("MV Motion Detection")

Select Case EventCode
Case 0
Text = "MV_ALGORITHM_START_EVENT"
Case 1
Text = "MV_ALGORITHM_END_EVENT"
Case 17
Text = "MV_MOTION_START_EVENT"
Case 18
Text = "MV_MOTION_END_EVENT"
Case 19
Text = "MV_RECORD_START_EVENT"
Case 20
Text = "MV_RECORD_END_EVENT"
End Select

txtMotion.Text = Text

error:
End If
End Sub


Thanks,

Teresa