在vb.net中使用aforge.net连接网络摄像头 [英] connecting a webcam using aforge.net in vb.net

查看:925
本文介绍了在vb.net中使用aforge.net连接网络摄像头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我是这个论坛的新手,也是一名初学程序员。



我希望在Visual Basic.NET中开发一个运动检测器程序。我已经尝试使用Windows API将网络摄像头连接到我的项目。

在网上冲浪时,我遇到了这个论坛,发现了一个使用AForge.net的项目。我下载并安装了框架并尝试了一个项目,以了解它是什么。

我决定自己重写代码,但在行中遇到错误

Hi everyone,

I am new to this forum and am a beginner programmer.

I wish to develop a motion detector program in Visual Basic.NET. I've tried the windows API for connecting the webcam to my project.
While surfing the net I came across to this forum and found a project which uses AForge.net. I downloaded and installed the framework and tried a certain project, to learn what is what.
I decided to rewrite the code myself, but encountered an error in the line

If VideoSourcePlayer1.Isrunning = True Then



它表示未声明 VideoSourcePlayer1 。由于其保护级别,它可能无法访问。



这是我要重写的代码。 VideoSourcePlayer1 没有错误。

我只是在重写代码,为什么我在遇到错误时会遇到错误对另一个项目很好吗?



请帮助我。



提前致谢。




It says that VideoSourcePlayer1 is not declared. It may be inaccessible due to its protection level.

Here is the code that I am trying to rewrite. The VideoSourcePlayer1 doesn't have an error.
I'm merely rewriting the code, so why am I encountering an error when it seems to work fine on the other project?

Kindly help me.

Thanks in advance.

Imports AForge.Video
Imports AForge.Video.DirectShow

Public Class MainWindow
    Dim VideoCaptureSource As VideoCaptureDevice
    Dim WCdevices As New FilterInfoCollection(FilterCategory.VideoInputDevice)


    Private Sub MainWindow_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        Dim MyWebcam As FilterInfo

        If WCdevices.Count = 0 Then
            lstWCdevices.Items.Add("No Webcam Device Detected")
        Else
            For Each MyWebcam In WCdevices
                lstWCdevices.Items.Add(MyWebcam.Name)
            Next
        End If
        lstWCdevices.SelectedIndex = 0
    End Sub



    Private Sub btnStart_Click(sender As Object, e As EventArgs) Handles btnStart.Click
        If lstWCdevices.SelectedItem <> "No Video Devices" Then


            If VideoSourcePlayer1.IsRunning = True Then
                VideoSourcePlayer1.SignalToStop()
                VideoSourcePlayer1.WaitForStop()
            End If

            VideoCaptureSource = New VideoCaptureDevice(VideoDevices(cboVideoSource.SelectedIndex).MonikerString)
            VideoSourcePlayer1.VideoSource = VideoCaptureSource
            VideoSourcePlayer1.Start()
        End If
    End Sub
End Class

推荐答案

您好,



您描述的错误 - 保护级别错误与范围有关。该对象: VideoSourcePlayer1 无法从您尝试调用它的类中访问。在你提供的代码中,我也没有看到它在任何地方声明。



我会查找它的声明,并确保它以这样一种方式声明它可以被你调用它的类 - 或者传递给它你需要拨打的课程。



希望这有帮助...



- Pete
Hello,

The error your describing - protection level errors are about scope. That object: VideoSourcePlayer1 is inaccessible from the class you are trying to call it from. In the code pieces you provided, I don't see it declared anywhere either.

I would look for it's declaration, and make sure it is being declared in such a way that it's available to the class you are calling it from - or pass it to the class you need to call it from.

Hope this helps...

- Pete


这是关键线,我想:



This is the key line here, I think:

Friend WithEvents VideoSourcePlayer1 As AForge.Controls.VideoSourcePlayer





这不仅仅是一个对象,它是第三方控件 - 它可以在 AForge 类中找到。它有事件 - 我想你可能没有处理它们。我认为您需要深入了解示例项目并找到事件的处理位置,并在您自己的项目中复制它。当你这样做时,我想你会得到视频。



我觉得你几乎就在那里......是的 - 只要判断你刚发布的内容,我就不会对你在设计师身上看不到什么感到惊讶。见:





It's not just an object, it's a 3rd party control - and it's found in the AForge class. It has Events - and I think you probably aren't handling them. I think you need to dig through the example project and find where the events are being handled, and replicate that in your own project. When you do that I think you will get video.

I think your almost there... And yes - just judging for what you just posted, I'm not surprised that you don't see anything in the designer. See this:

Me.videoSourcePlayer1.Location =...





他们手动定位控件。设计师你可能看不到任何东西。



- Pete



They're positioning the control manually. There probably isn't anything in the designer you'll see.

- Pete


伙计们,我终于找到了这个VideoSourcePlayer1 。所以这是一个必须首先在工具箱中添加的对象。我做的是,右键单击工具箱>选择项目>浏览并添加aforge.controls.dll,然后出现包括VideoSourcePlayer在内的组件,就是这样:)谢谢你的帮助。
Guys, i finally found this VideoSourcePlayer1. So this is an object that you have to add first in the toolbox. what i did is, right click the toolbox > Choose Items > Browse and add the aforge.controls.dll, then components including VideoSourcePlayer appeared and that's it :) thank you for helping.


这篇关于在vb.net中使用aforge.net连接网络摄像头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆