Sunday 24 November 2013

Getting the webcam working ...

This was a lot more complicated than I first thought, there is example code on the Internet to capture images from webcams but not all of it works on Windows 8.1 64 bit with Microsoft Visual Studio Express 2013 Desktop, C#.

To cut a long story short I found that you need to use Windows Image Acquisition (WIA), which uses the Windows Driver Model (WDM) architecture.

Again this is just another piece of test code which will need stitching into a main application but what is does do in only a few lines of code is:
  1. Switches on the webcam so you can see the live video feed from the webcam
  2. Enables you to take a picture and automatically save it as a JPEG on your hard drive
  3. Switches off the webcam 

Webcam video and image capture


Using the example code that Samuel dos Anjos has written (link below) I simply added a new button 'Take Picture' to the Form and added a takePic function to the userControl class.

Calling the new Save Image functionality


The video feed is displayed via a PictureBox (ImgWebCam) control in Samuel's example so all I needed to do is use that control to save its current image as a JPEG.

Saving the current image as a JPEG


The earlier code can then pick up that JPEG and start analysing it.  The fact that you can see the live webcam video feed as the Robot arm is moving the webcam to take the picture will I'm sure look pretty cool!


Some useful example code from Samuel dos Anjos:

No comments:

Post a Comment