使用 DirectShow 和 DirectX.Capture C# 从 EasyCap 4ch USB DVR 设备捕获摄像头馈送
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18947263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Capture Camera Feed from EasyCap 4ch USB DVR Device using DirectShow and DirectX.Capture C#
提问by Yaser Jaradeh
I'm trying to capture the camera feed from an EasyCap 4 Channel USB DVR Devicethat i got recently
and i have bought a super Mimi Monochrome/Color Camera and connected it to the DVR Device and managed to correctly setup the device with the driver "SMI Grabber"and installed the software that comes with the Device "SuperViewer"
and i have wrote a simple windows form application that contains a PictureBox
to priview the camera feed
(There is an edit in the bottom)
The Code:
我正在尝试从我最近获得的EasyCap 4 通道 USB DVR 设备捕获摄像机信号,我
购买了一个超级 Mimi 单色/彩色摄像机并将其连接到 DVR 设备并设法使用驱动程序正确设置设备“ SMI Grabber”并安装了“SuperViewer”设备随附的软件,
我编写了一个简单的 Windows 窗体应用程序,其中包含一个PictureBox
用于预览相机源
(底部有一个编辑)
的代码:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DirectX.Capture;
namespace DirectShowWithCrossbar
{
public partial class Form1 : Form
{
private CrossbarSource crossbar;
private Filters filters;
private Capture capture;
public Form1()
{
InitializeComponent();
filters = new Filters();
capture = new Capture(filters.VideoInputDevices[0], filters.AudioInputDevices[0]);
foreach (Filter device in filters.VideoInputDevices)
{
comboBox1.Items.Add(device);
}
if (comboBox1.Items.Count > 0)
comboBox1.SelectedIndex = 0;
foreach (Filter device in filters.AudioInputDevices)
{
comboBox2.Items.Add(device);
}
if (comboBox2.Items.Count > 0)
comboBox2.SelectedIndex = 0;
foreach (Source source in capture.VideoSources)
{
comboBox3.Items.Add(source);
}
if (comboBox3.Items.Count > 0)
comboBox3.SelectedIndex = 0;
ShowPropertPagesInMenuStrip();
crossbar = (CrossbarSource)capture.VideoSource;
crossbar.Enabled = true;
capture.PreviewWindow = pictureBox1;
}
private void ShowPropertPagesInMenuStrip()
{
foreach (PropertyPage pro in capture.PropertyPages)
{
menusToolStripMenuItem.DropDownItems.Add(new ToolStripMenuItem(pro.Name));
}
}
private void button1_Click(object sender, EventArgs e)
{
capture.Cue();
capture.Start();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
capture.Stop();
capture.Dispose();
}
private void comboBox3_SelectedIndexChanged(object sender, EventArgs e)
{
capture.VideoSource = (Source)comboBox3.SelectedItem;
}
}
}
and i got a black screen in the picture box ??and by mistake after closing my application i ran the SuperViewerapplication that comes with the DVR deviceand then open my application then my picture box began to show me the feed from the camera, strange!!!and the feed from the original software freezes !!
DirectX.Capture Example and Sources tried with the same result http://www.codeproject.com/Articles/3566/DirectX-Capture-Class-Library
and i have also used OpenCVand Touchlessand i got the same result :(
Edit:
I have been searching and found that i need to get the filter (IAMCrossbar) i think that is the problem DirectShow USB webcam changing video sourceand after appling the changes in this link in the DirectX.CaptureWrapper i still get the same results :(
Thanks for any help in advance Yaser
我在图片框中有一个黑屏??在关闭我的应用程序后,我错误地运行了DVR 设备附带的SuperViewer应用程序,然后打开我的应用程序,然后我的图片框开始向我显示来自相机的提要,奇怪!!!原始软件的提要冻结了!!
DirectX.Capture Example 和 Sources 尝试了相同的结果http://www.codeproject.com/Articles/3566/DirectX-Capture-Class-Library并且我还使用了OpenCV和Touchless,我得到了相同的结果:(编辑:我一直在搜索,发现我需要获取过滤器(IAMCrossbar)我认为这是问题所在
DirectShow USB 网络摄像头更改视频源并在DirectX.CaptureWrapper中应用此链接中的更改后,我仍然得到相同的结果:(
感谢您提前提供任何帮助 Yaser
回答by Usman
If your capture device has option, to select one from multiple input interfaces, then yes, you are right about, that you needed to use IAMCrossbar.
如果您的捕获设备有选项,可以从多个输入接口中选择一个,那么是的,您是对的,您需要使用 IAMCrossbar。
If you want to stick to Directshow( as others have suggested OpenCV), then I would suggest,
如果您想坚持使用 Directshow(正如其他人建议的 OpenCV),那么我建议,
- Try building all capturing related code in a C++/CLI dll,
- Build all your UI in C#.
- 尝试在 C++/CLI dll 中构建所有捕获相关代码,
- 用 C# 构建所有 UI。
You can take this MP3 Player Sample Projectas starting point for your dll.
您可以将此MP3 播放器示例项目作为 dll 的起点。
For capturing, AmCapis a detailed example.
对于捕获,AmCap是一个详细示例。
What I mean is that you need to get the capturing code out of AmCap into above MP3 Player Sample dll, and expose it to your C# application.
我的意思是,您需要将 AmCap 中的捕获代码放入上面的 MP3 播放器示例 dll 中,并将其公开给您的 C# 应用程序。