VB.Net慢速PictureBox图像上的Emgu.CV

VB.Net慢速PictureBox图像上的Emgu.CV,vb.net,winforms,emgucv,Vb.net,Winforms,Emgucv,使用Emgu.CV版本2.2.1.1150 我正在尝试在图片框上查询帧和显示,该代码在带有Microsoft LifeCam 720p Picturebox的台式计算机上运行良好。Picturebox平滑流畅,但在Windows 10平板电脑(CHUWI HI10X)上尝试该程序时,图像滞后 如果我在Win10摄像头应用程序中测试平板电脑摄像头,它们工作得很好,视频高清流畅 我更新了这些摄像头的驱动程序,检查是否是这样,但没有运气 Public Class frmCamera Dim imgFr

使用Emgu.CV版本2.2.1.1150

我正在尝试在图片框上查询帧和显示,该代码在带有Microsoft LifeCam 720p Picturebox的台式计算机上运行良好。Picturebox平滑流畅,但在Windows 10平板电脑(CHUWI HI10X)上尝试该程序时,图像滞后

如果我在Win10摄像头应用程序中测试平板电脑摄像头,它们工作得很好,视频高清流畅

我更新了这些摄像头的驱动程序,检查是否是这样,但没有运气

Public Class frmCamera
Dim imgFrame As Image(Of Bgr, Byte)
Dim vidCapture As Capture

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    vidCapture = New Capture(1)
    vidCapture.QueryFrame()
    AddHandler Application.Idle, AddressOf AppIdle
End Sub

Public Sub AppIdle(ByVal sender As System.Object, ByVal e As System.EventArgs)
    imgFrame = vidCapture.QueryFrame().Resize(800, 600, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR)
    PictureBox1.Image = imgFrame.ToBitmap()
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    frmMain.Show()
    RemoveHandler Application.Idle, AddressOf AppIdle
    vidCapture.Dispose()
    Me.Close()
End Sub 
末级

我尝试了多种帧大小和不同的插值类型,但没有成功。也从使用imageBoxFrameGrabber更改为PictureBox转换为位图,但结果仍然相同。我也试过使用计时器,但那看起来更糟

谢谢

编辑:

使用计时器,我的代码就这样结束了,没有运气

Public Class frmCamera
Dim imgFrame As Image(Of Bgr, Byte)
Dim vidCapture As Capture

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Timer1.Interval = Timer1.Interval
    RichTextBox1.Text = "Interval:" + Convert.ToString(Timer1.Interval)
    Timer1.Start()
    vidCapture = New Capture(1)
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
    frmMain.Show()
    vidCapture.Dispose()
    Me.Close()
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    imgFrame = vidCapture.QueryFrame().Resize(800, 600, Emgu.CV.CvEnum.INTER.CV_INTER_LINEAR)
    ' PictureBox1.Image.Dispose()
    PictureBox1.Image = imgFrame.ToBitmap()
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Timer1.Stop()
    Timer1.Interval = Timer1.Interval + 2
    RichTextBox1.Text = "Interval:" + Convert.ToString(Timer1.Interval)
    Timer1.Start()
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Timer1.Stop()
    Timer1.Interval = Timer1.Interval - 2
    RichTextBox1.Text = "Interval:" + Convert.ToString(Timer1.Interval)
    Timer1.Start()
End Sub
末级

尝试按建议在图片框中处理图像,结果是:

System.NullReferenceException:“对象引用未设置为对象的实例。”

在处置的时候


再次感谢吉米

当您使UI元素无效时,调用Application.Idle的次数太多,例如设置PictureBox.Image属性(~20000次以上/秒)。使用计时器(以便定义/调整帧速率)。如果计时器没有按预期工作,请发布该代码。顺便说一句,
Image.ToBitmap()
应该返回一个新对象,因此您应该有
PictureBox1.Image?.Dispose()PictureBox1.Image=imgFrame.ToBitmap()
。编辑问题以添加计时器代码。还请注意,我捕获的两个按钮是计时器间隔,因此我可以上下尝试不同的按钮,但我尝试了从2到300的时间,但没有成功。我没有编写
PictureBox1.Image.Dispose()
,而是编写了
PictureBox1.Image?.Dispose()
。如果您有该语言的旧版本,请在
中更改它,如果PictureBox1.Image不是PictureBox1.Image.Dispose()
。不清楚什么是计时器。时间间隔设置为,使用此计时器的结果是什么,或者您有什么实际问题。把50毫秒左右的间隔缩短到至少35毫秒。哦,这个问号起作用了。但是画面仍然显示得有点滞后,拖尾,缓慢。我不知道该怎么形容它。不过,它只是在平板电脑摄像头上,如果我在网络摄像头上试用,效果会很好。至于时间间隔,我把它设为20,然后用按钮上下移动,看看哪个时间间隔效果最好,但它们都不起作用。希望我能拍一段视频给你看。更新:似乎我的摄像头驱动程序不正确,而windows摄像头应用程序似乎工作顺利,但我的EMGU.CV应用程序却没有。我安装了原始驱动程序,现在可以很好地使用计时器。