【问题标题】:Extracting motion detector blob提取运动检测器 blob
【发布时间】:2019-11-07 17:23:24
【问题描述】:

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

我不仅想检测运动,还想读取帧中运动发生的位置。 MotionDetector 中似乎没有任何关于其位置的信息。我想也许我可以通过MotionDetector 运行它,然后提取最大的 blob,但这似乎也不起作用。它只拾取一个 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】:

    这还没有结束,但我实际上可以与 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-06
      • 2019-11-21
      • 1970-01-01
      • 1970-01-01
      • 2021-10-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多