accord-net / framework

Machine learning, computer vision, statistics and general scientific computing for .NET
http://accord-framework.net
GNU Lesser General Public License v2.1
4.49k stars 1.99k forks source link

videosourceplayer does not play unless there is an eventhandler for it #1180

Open gtsiros opened 6 years ago

gtsiros commented 6 years ago

this is my first ever post on github add the latest alpha of Accord (which is awesoooome \m/) to a windows forms vb project in vs 2015 and dump this code inside the class definition run and then run it again after uncommenting the addhanlder line What would you like to submit? (put an 'x' inside the bracket that applies)

Dim p As Accord.Controls.VideoSourcePlayer
Sub f(o As Object, e As EventArgs) Handles MyBase.Shown
    Dim fic As New Accord.Video.DirectShow.FilterInfoCollection(Accord.Video.DirectShow.FilterCategory.VideoInputDevice)
    '''' try 0 or something
    Dim c As New Accord.Video.DirectShow.VideoCaptureDevice(fic(1).MonikerString)
    p = New Accord.Controls.VideoSourcePlayer With {
        .VideoSource = c,
        .Dock = DockStyle.Fill
    }
    Controls.Add(p)
    '''' try it with and without commenting out the following line
    'AddHandler p.NewFrameReceived, AddressOf h 
    p.Start()
End Sub

Sub h(o As Object, e As Accord.Video.NewFrameEventArgs)
    ' does nothing
End Sub

Sub g(o As Object, e As FormClosingEventArgs) Handles MyBase.FormClosing
    '''' just so you don't have to press the red square yourself
    p.SignalToStop()
    p.WaitForStop()
End Sub
alecjames commented 6 years ago

I have the same issue running sample application "Two cameras".

On Win7 x64 VS2013, build the sample application as received, with 2 connected USB cameras, after pressing "start" no video is displayed. After googling and finding this issue #1180, when I add dummy event handlers in the MainForm constructor, the sample behaves as expected.

videoSourcePlayer1.NewFrameReceived += videoSourcePlayer1_NewFrameReceived; videoSourcePlayer2.NewFrameReceived += videoSourcePlayer2_NewFrameReceived;

MichaelFCoyle commented 4 years ago

I can verify the same behaviour in a custom application I am writing. The VideoSourcePlayer control was not playing, and I added the NewFRameReceived event handler and it began working with no other code changes to the application. v3.8.2-alpha