Edit: Motion Detection I believe this may answer my question...
I want to not only detect motion, but read where the motion occurred in the frame. Nothing in MotionDetector
seems to have anything about its location. I thought maybe I could run it through MotionDetector
then extract the biggest blob, but that doesn't seem to work either. It only picks up one blob.
Video clip is a vehicle coming down a ramp. mainPBX is the original frame, main2PBX is the altered frame (with the biggest blob overlayed). My thought is to read when the blob goes from smaller to bigger (and vice versa), to determine entering or leaving.
Private Sub Processor()
Dim bc As New BlobCounter With {
.MinWidth = 5,
.MinHeight = 5,
.ObjectsOrder = ObjectsOrder.Size
}
Dim detector As New MotionDetector(New SimpleBackgroundModelingDetector, New MotionAreaHighlighting)
Using reader As New AForge.Video.FFMPEG.VideoFileReader()
reader.Open("C:\Videos\MyVideo.mp4")
For i As Integer = 0 To reader.FrameCount - 1
Dim frame = reader.ReadVideoFrame()
Dim frame2 As Bitmap = frame.Clone()
Dim frame3 As Bitmap = frame.Clone()
detector.ProcessFrame(frame2)
bc.ProcessImage(frame2)
Dim blobs = bc.GetObjectsInformation()
If blobs.Length > 0 Then
bc.ExtractBlobsImage(frame3, blobs(0), True)
PBX_Image(main2PBX, frame3.Clone())
End If
PBX_Image(mainPBX, frame.Clone())
Threading.Thread.Sleep(25)
frame.Dispose()
frame2.Dispose()
frame3.Dispose()
Next
End Using
End Sub