简体   繁体   中英

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
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:

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!!! 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
and i have also used OpenCV and Touchless and 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 source and after appling the changes in this link in the DirectX.Capture Wrapper i still get the same results :(
Thanks for any help in advance 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.

If you want to stick to Directshow( as others have suggested OpenCV), then I would suggest,

  1. Try building all capturing related code in a C++/CLI dll,
  2. Build all your UI in C#.

You can take this MP3 Player Sample Project as starting point for your dll.

For capturing, AmCap is a detailed example.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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