简体   繁体   English

使用 DirectShow 和 DirectX.Capture C# 从 EasyCap 4ch USB DVR 设备捕获摄像头馈送

[英]Capture Camera Feed from EasyCap 4ch USB DVR Device using DirectShow and DirectX.Capture C#

I'm trying to capture the camera feed from an EasyCap 4 Channel USB DVR Device that i got recently我正在尝试从我最近获得的EasyCap 4 通道 USB DVR 设备中捕获摄像机信号
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"我买了一个超级咪咪单色/彩色相机并将其连接到 DVR 设备并设法使用驱动程序“SMI Grabber”正确设置设备并安装了设备“SuperViewer”附带的软件
and i have wrote a simple windows form application that contains a PictureBox to priview the camera feed我编写了一个简单的 Windows 窗体应用程序,其中包含一个用于显示相机提要的PictureBox
(There is an edit in the bottom) (底部有编辑)
The Code:代码:

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 SuperViewer application that comes with the DVR device and then open my application then my picture box began to show me the feed from the camera, strange!!!在关闭我的应用程序后,我错误地运行了DVR 设备附带的SuperViewer应用程序,然后打开我的应用程序,然后我的图片框开始向我显示来自相机的提要,奇怪!!! and the feed from the original software freezes !!原始软件的提要冻结了!!
我的软件和运行我的 SuperViewer 都在工作,另一个正在冻结 DirectX.Capture Example and Sources tried with the same result http://www.codeproject.com/Articles/3566/DirectX-Capture-Class-Library DirectX.Capture Example 和 Sources 尝试了相同的结果http://www.codeproject.com/Articles/3566/DirectX-Capture-Class-Library
and i have also used OpenCV and Touchless and i got the same result :(而且我还使用了OpenCVTouchless ,我得到了相同的结果:(
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 source and after appling the changes in this link in the DirectX.Capture Wrapper i still get the same results :(我一直在搜索并发现我需要获取过滤器(IAMCrossbar)我认为这是DirectShow USB 网络摄像头更改视频源的问题,在DirectX.Capture Wrapper 中应用此链接中的更改后,我仍然得到相同的结果:(
Thanks for any help in advance Yaser感谢您提前提供任何帮助Yaser

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),那么我建议,

  1. Try building all capturing related code in a C++/CLI dll,尝试在 C++/CLI dll 中构建所有捕获相关代码,
  2. Build all your UI in C#.用 C# 构建所有 UI。

You can take this MP3 Player Sample Project as starting point for your dll.您可以将此MP3 播放器示例项目作为 dll 的起点。

For capturing, AmCap is 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# 应用程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM