简体   繁体   中英

capture image from webcam c# WPF app

I'm trying to capture images from a webcam for one application in WPF/C#

1) I tried WIA but i het the error 0x80210015, I have read that this error occurs when there is no WIA device available. I read that in windows vista/7 WPD is used insted WIA but when i try a simple example

PortableDeviceManager deviceManager = new PortableDeviceManager();
deviceManager.RefreshDeviceList();

uint numberOfDevices = 1;

deviceManager.GetDevices(null, ref numberOfDevices);

if (numberOfDevices == 0)
{
    Console.WriteLine("No device");
}
else
{
    string[] deviceIds = new string[numberOfDevices];
    deviceManager.GetDevices(ref deviceIds[0], ref numberOfDevices);

    Console.WriteLine(deviceIds);
}

Console.Read();

i cant detect devices.

2) I triead with http://easywebcam.codeplex.com/ works, but i get randomly the error "An error occured while capturing the video image. The video captu..." and i need select the device always and i need execute webcam.start() several times (2 or 3) for that camera works.

I have two webcams

  • Chicony Web 2.0 (inbuilt webcam)
  • Genius FaceCam 2000

here is a simple take a picture kind of program

  Image<Bgr, Byte> img; 
    private Capture capture;
    private bool captureInProgress;

    private void gumb_kamera_Click(object sender, EventArgs e)
    {

    }

    private void processFunction(object sender, EventArgs e)
    {
         img = capture.QueryFrame();

       //  imageBox1.Image = img;
    }

    private void Form1_Load(object sender, EventArgs e)
    {
        if (capture == null)
        {
            try
            {
                capture = new Capture(0);
            }
            catch (NullReferenceException excpt)
            {
                MessageBox.Show(excpt.Message);
            }
        }

        if (capture != null)
        {
            if (captureInProgress)
            {
                Application.Idle -= processFunction;
            }
            else
            {
                Application.Idle += processFunction;
            }
            captureInProgress = !captureInProgress;
        }



    }

    private void button1_Click(object sender, EventArgs e)
    {



    imageBox1.Image = img; 

    }

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