网络摄像头、C# 和可靠的包装器

发布于 2025-01-01 22:28:42 字数 410 浏览 0 评论 0原文

我迫切需要替换 C# 应用程序中使用的包装器。基本上,我们需要做的是将网络摄像头附加到两个图片框之一。这将用于通过按下按钮来拍摄静态图像,这可能会分离相机源并将静态图像附加到该图片框,然后稍后重新附加相机源。我们之前找到了一些免费代码,可以与 CaptureDevice.cs 文件和 Pinvoke.dll 结合使用,将其绑定到 avicap32.dll 中。不幸的是,这似乎存在随机、间歇性错误,无法可靠地重现。实在是太片状了。在某个随机时刻,其中一个图片框可能会变黑,并且在拍摄照片之前不会显示提要,此时正确的图片将附加到图片框。然后,即使只连接了一个网络摄像头,它也会不断提示选择网络摄像头,否则它不会这样做。

坦率地说,我对 Microsoft 没有在 .NET 中包含任何内容来覆盖网络摄像头视频源感到惊讶和沮丧。我正在寻找可靠且相对简单的方法来取代这个有缺陷的网络摄像头系统。

I'm in dire need of a replacement for a wrapper being used in a C# application. Basically, what we need to do is attach a webcam feed to one of two picture boxes. This will be used to take still images at the push of a button, which may detach the camera feed and attach the still image to that picture box, then reattach the camera feed later. We had previously found some free code to utilize with a CaptureDevice.cs file and Pinvoke.dll to tie it into avicap32.dll. Unfortunately, this seems to have random, intermittent errors that cannot be reliably reproduced. It's just too flaky. At some random point, one of those picture boxes may go black and won't show the feed until the picture is taken, at which point the proper picture is attached to the picture box. Then, even if there's only one webcam attached, it'll keep prompting for the webcam to be selected, something it wouldn't do otherwise.

Quite frankly, I'm surprised and dismayed that Microsoft hasn't included anything in .NET to cover webcam video feeds. I'm looking for something reliable and relatively simple to implement to replace this buggy webcam system.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

套路撩心 2025-01-08 22:28:42

我可以建议

http://www.emgu.com/wiki/index.php/Main_Page< /a>

我已经在许多 C++ 库中使用了 OpenCV,并且从我尝试过的其他东西来看,它似乎非常适合网络摄像头。 Emgu 只是 OpenCV 的 C# 包装器。

这是一个可供尝试的示例项目。它非常基本且简单,但应该可以立即使用。

http://dl.dropbox.com/u/18919663/vs%20samples /OpenCVCSharpTest.zip(刚刚上传)

示例:

using Emgu.CV;
using Emgu.CV.Structure;
...

public partial class Form1 : Form
{
    public Capture cvWebCam;
    public Form1()
    {
        InitializeComponent();

        try
        {
            cvWebCam = new Capture();
            timer1.Start();
        }
        catch
        {
            Console.WriteLine("Default camera not found or could not start");
        }
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        if (cvWebCam != null)
        using (Emgu.CV.Image<Bgr, byte> frame = cvWebCam.QueryFrame())
        {
            pictureBox1.BackgroundImage = frame.ToBitmap();
        }
    }
}

May I suggest

http://www.emgu.com/wiki/index.php/Main_Page

I have used OpenCV in many C++ libraries and it seems to work very well for webcams from other things I've tried. Emgu is just a C# wrapper for OpenCV.

Here is a sample project to try it out on. It's very basic and simple, but should work right away.

http://dl.dropbox.com/u/18919663/vs%20samples/OpenCVCSharpTest.zip (just uploaded)

Sample:

using Emgu.CV;
using Emgu.CV.Structure;
...

public partial class Form1 : Form
{
    public Capture cvWebCam;
    public Form1()
    {
        InitializeComponent();

        try
        {
            cvWebCam = new Capture();
            timer1.Start();
        }
        catch
        {
            Console.WriteLine("Default camera not found or could not start");
        }
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        if (cvWebCam != null)
        using (Emgu.CV.Image<Bgr, byte> frame = cvWebCam.QueryFrame())
        {
            pictureBox1.BackgroundImage = frame.ToBitmap();
        }
    }
}
oО清风挽发oО 2025-01-08 22:28:42

尝试 DirectShow.net - 它是一个免费的包装库,用于从 .NET 访问 DirectShow 功能:
http://directshownet.sourceforge.net

其代码示例还包含一个用于从网络摄像头捕获视频的示例应用程序:
http://sourceforge.net/projects/directshownet/files/DirectShowSamples/

Try DirectShow.net- it's a free wrapper library to access DirectShow functionality from .NET:
http://directshownet.sourceforge.net

Its code samples contain a sample app for capturing video from webcams, too:
http://sourceforge.net/projects/directshownet/files/DirectShowSamples/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文