捕获框架 webcam 通过 DirectShow.NET

我是新的b。 DirectShow, 因此,这个库的某些部分我不太了解。
我已经看到了一个例子 DxSnap, 但是我需要

捕获框架而不先前

, 为了进一步处理。 我怎样才能做到这一点?
已邀请:

二哥

赞同来自:

如果你的主要关注点 "access webcam", 但不是" 使用权 webcam 从 DirectShow", 然后我会看看
http://www.aforgenet.com/framework/
. 一旦我试图用它 DirectShow 只有在更短的时间内和较少的代码中找出可以用几个视频源进行操作。

这是一个示例代码:
http://www.aforgenet.com/frame ... .html

石油百科

赞同来自:

你可以自己建造它。 如果你看文件夹 windows sdk 7.0~, 你可以去 samples > multimedia > directshow >, 并且应该有一个文件夹 filters, 这将向您展示如何创建通用过滤器并执行您想要的内容

小明明

赞同来自:

这是一个例子。 建造形状 Windows, 如图所示。

https://i.stack.imgur.com/GWHBP.png
WinForm

自己 WinForm 叫

Form1

标签" Recording ... " 叫

lblRecording

ComboBox 叫

cbCameraDevices

名称按钮 "Stop" 有一个按钮

button1

"Copy" 按钮的名称

button2

"Start" 按钮的名称

btnStartVideo

还有 pictureBox 名称 pictureBox1

,

其中将显示视频。

这些名称允许您关联事件处理程序 /在较低的地方/ 使用适当的控制元素。

如果程序成功构建和运行,请使用

combobox

选择一个实惠的来源。 按下按钮 "

开始

", 查看视频流。 按下按钮 "

复制

", 将图像克入剪贴板。 按下按钮 "

停止

", 关闭图像磁带。

该代码已测试 Microsoft:

Windows 10-X64 /车 Intel/

Visual Studio 2017 社区

.NET 框架 4.5.

要构建代码,包含此代码的项目应具有以下内容

链接

:

AForge.Video.DirectShow

AForge.Video

AForge

包可以绘制到项目中 NuGet. 在 Visual Studio IDE:

工具 - >

NuGet 包管理员 ->

包装管理 NuGet 对于解决方案......

找 "AForge" 并安装相应的包。

代码:


using System;
using System.Drawing;
using System.Windows.Forms;
using CameraDevice;
using AForge.Video.DirectShow;
using System.Threading;

namespace CameraCaptureTest3
{
public partial class Form1 : Form
{
CameraImaging camImg;
bool StopVideo = true;
Thread thrVideo;
object mImageLock;
FilterInfoCollection videoDevices;

public Form1//
{
InitializeComponent//;
camImg = new CameraImaging//;
mImageLock = new object//;
// enumerate video devices
videoDevices = new FilterInfoCollection/FilterCategory.VideoInputDevice/;
cbCameraDevices.Items.Clear//;
foreach/FilterInfo i in videoDevices/ cbCameraDevices.Items.Add/i.Name/;
}

//---------------------------------------------------------
// VideoRecordin// is meant to be run on a separate thread
//---------------------------------------------------------
private void VideoRecording//
{
camImg.videoSource.Start//;

while /!StopVideo/
{
lock /mImageLock/
{
Bitmap tmp = /Bitmap/camImg.bitmap.Clone//;

if /InvokeRequired/
{
BeginInvoke/new MethodInvoker/// =>
{
pictureBox1.Image = tmp;
pictureBox1.Invalidate//;
}//;
}
else
{
pictureBox1.Image = tmp;
pictureBox1.Invalidate//;
}
}
Thread.Sleep/33/;
}
camImg.videoSource.Stop//;
}

private void btnStartVideo_Click/object sender, EventArgs e/
{
StopVideo = false;
try
{
camImg.videoSource = new VideoCaptureDevice/camImg.videoDevices[cbCameraDevices.SelectedIndex].MonikerString/;
thrVideo = new Thread/VideoRecording/;
thrVideo.Start//;
Thread.Sleep/1000/;
lblRecording.Visible = true;
}
catch /Exception/
{
MessageBox.Show/"No camera is chosen.", "Exception", MessageBoxButtons.OK, MessageBoxIcon.Exclamation/;
}
}

private void Form1_FormClosing/object sender, FormClosingEventArgs e/
{
StopVideo = true;
if /thrVideo != null/ thrVideo.Join//;
lblRecording.Visible = false;
Application.DoEvents//;
}

private void button1_Click/object sender, EventArgs e/
{
StopVideo = true;
if /thrVideo != null/
while /thrVideo.ThreadState == ThreadState.Running/
Application.DoEvents//;
pictureBox1.Image = null;
lblRecording.Visible = false;
}

private void button2_Click/object sender, EventArgs e/
{
Clipboard.SetImage/pictureBox1.Image/;
}
}
}

要回复问题请先登录注册