Articles → .NET → Detect Webcam Programmatically In C#

Detect Webcam Programmatically In C#







  1. First of all download the DLLs from AForge.NET website - ‘http://www.aforgenet.com/framework/downloads.html
  2. Once the DLLs are downloaded lets create a windows based application (You can use console based application as well). See the screenshot below for project structure
  3. Picture showing the folder structure of a windows based application in visual studio solution explorer
    Click to Enlarge

  4. Add the reference of following DLLs in the project
    1. AForge.Video.dll
    2. AForge.Video.DirectShow
  5. Add following name space in ‘Form1.cs’
  6. using AForge.Video.DirectShow;


  7. Add a button on the screen with the caption ‘Detect’ and write the following code on button click event
  8. private FilterInfoCollection devices;
    string IsWebCamExists = "NOT EXIST";
    private void btnDetectWebcam_Click(object sender, EventArgs e) {
      devices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
    
      if (devices.Count > 0)
        IsWebCamExists = "EXIST";
    
      MessageBox.Show(string.Format("Webcam Status: {0}", IsWebCamExists));
    }





Posted By  -  Karan Gupta
 
Posted On  -  Friday, January 23, 2015

Query/Feedback


Your Email Id
 
Subject
 
Query/FeedbackCharacters remaining 250