提取运动检测器斑点

问题描述 投票:0回答:1

编辑:Motion Detection我相信这可以回答我的问题...

我不仅要检测运动,还要读取帧中运动发生的位置。 MotionDetector中似乎没有任何内容。我以为也许可以通过MotionDetector运行它,然后提取最大的blob,但这似乎也不起作用。它只会拾取一个斑点。

视频剪辑是从坡道上下来的车辆。 mainPBX是原始帧,main2PBX是更改后的帧(覆盖了最大的blob)。我的想法是阅读blob从小到大的过程(反之亦然),以确定进入还是离开。

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
aforge
1个回答
0
投票

这还没有完成,但实际上我可以与Blob进行交互。

Private Sub Processor()
    Dim Rectangles As New List(Of Rectangle)

    Dim detector As New SimpleBackgroundModelingDetector With {
        .SuppressNoise = True,
        .DifferenceThreshold = 10,
        .FramesPerBackgroundUpdate = 10,
        .KeepObjectsEdges = True
    }

    Dim processor As New AForge.Vision.Motion.BlobCountingObjectsProcessing With {
        .MinObjectsWidth = 40,
        .MinObjectsHeight = 40,
        .HighlightColor = Color.Red
    }

    Dim motionDetector As New MotionDetector(detector, processor)

    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()
            motionDetector.ProcessFrame(frame)
            Dim t As BlobCountingObjectsProcessing = motionDetector.MotionProcessingAlgorithm
            Dim r As Rectangle = Rectangle.Empty
            If t.ObjectRectangles.Length > 0 Then
                If t.ObjectRectangles.Length > 2 Then
                    r = t.ObjectRectangles.Aggregate(Function(r1, r2) If((r1.Width * r1.Height) > (r2.Width * r2.Height), r1, r2))
                Else
                    r = t.ObjectRectangles.First()
                End If
            End If

            If r.IsEmpty = False Then Rectangles.Add(r)

            PBX_Image(mainPBX, frame.Clone())

            Threading.Thread.Sleep(25)

            frame.Dispose()
        Next
    End Using
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.