在C#中使用网络摄像头 [英] Webcam usage in C#

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

问题描述

我在C#中做节目连接到一个网络摄像头,并做一些图像处理它。
我有一个使用的Win32 API(avicap32.dll)连接到网络摄像头和发送消息给它,它发送到剪贴板上工作的应用程序。现在的问题是,虽然油漆入店,从空指针程序结果阅读。

I am making a program in C# to connect to a webcam and do some image manipulation with it. I have a working application that uses win32 api (avicap32.dll) to connect to the webcam and send messages to it that sends it to the clipboard. The problem is that, while accesible from paint, reading it from the program results in null pointers.

这是code口用于连接网络摄像头:

This is the code I use to connect the webcam:

mCapHwnd = capCreateCaptureWindowA("WebCap", 0, 0, 0, 320, 240, 1024, 0);

SendMessage(mCapHwnd, WM_CAP_CONNECT, 0, 0);
SendMessage(mCapHwnd, WM_CAP_SET_PREVIEW, 0, 0);

这是我使用的图像复制到剪贴板:

And this is what I use to copy the image to the clipboard:

SendMessage(mCapHwnd, WM_CAP_GET_FRAME, 0, 0);

SendMessage(mCapHwnd, WM_CAP_COPY, 0, 0);
tempObj = Clipboard.GetDataObject();
tempImg = (System.Drawing.Bitmap)tempObj.GetData(System.Windows.Forms.DataFormats.Bitmap);

即使世界这是我从code去掉了一些错误检查,使其更短。

Theres some error checking which I have removed from the code to make it shorter.

在此先感谢:)

推荐答案

我最近开始做一些爱好这方面的工作。

I've recently started doing some hobby work in this area.

我们定居在使用 OpenCV的库与的 opencvdotnet 包装。它支持从摄像头录制帧:

We settled on using the OpenCV library with the opencvdotnet wrapper. It supports capturing frames from a webcam:

using (var cv = new OpenCVDotNet.CVCapture(0))
{
    var image = cv.CreateCompatibleImage();
    // ...
    cv.Release();
}

如果你正在做的图像处理,OpenCV的的图像处理算法已换了OpenCVDotNet.Algs组件内。

And if you're doing image manipulation, OpenCV's image processing algorithms have been wrapped within the OpenCVDotNet.Algs assembly.

如果你决定走这条路,一定要安装OpenCV 1.0版(并安装到C:\\ Program Files文件\\ OpenCV的,如果你是在Vista 64位,或MKLINK OpenCV的C:\\ Program Files文件(86)\\ OpenCV`从正确的目录,否则opencvdotnet不会安装)。

If you decide to go this route be sure to install OpenCV version 1.0 (and install it to "c:\program files\opencv" if you are on Vista 64-bit, or "mklink OpenCV 'c:\program files (x86)\OpenCV`" from the correct directory or else opencvdotnet will not install).

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

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