Last tutorial we saw about setting up the environment to use AForge.NET. That was not a necessary tutorial, but it was my first post to see how to use windows live writer tool. And also that will give a sense satisfaction for people who have used OpenCV and trying AForge for the first time.
So now we have a window look like this. ( you can refer the previous tutorial to see how we set this environment).
Now the fun part. Programming !!!!!!!!!!!!!!!!!!!!!!!!!!
I am an Electrical guy, therefore according to records I am not a good programmer.
Press the “F7” function key to go the see the code of this form.
[or] right click on the form and select “View Code”
It is the same.
We will see a page like this
This is called the “code behind”. The previous one is called the “design view”. These are non standard terminologies used in programming environment. Just keep yourself updated because we’ll be using this in the upcoming tutorials.
Add these two namespaces
Before we use the webcam the code has to see the webcam (or ) the program has to know that there is a web cam attached to the computer. So here is our first aim
Aim : To list the USB camera attached to my computer
Put a button in the form. So when we click on the button, it is going to popup box for each camera.
Double click on the button and it will create a function. They call it the event handler. So when the applications is running and we click on the button, it will go to this function.
Now we are going to add code into this function so when we click the button it should list the USB camera attached to this computer (or laptop in my case). I will add the code and then explain the code with inline comments. I don’t want to add more screenshots and make this boring. So look at the following screenshot and try to read and understand the inline comments which will explain what is what.
Now lets compile the code using the shortcut key (im sorry, im used to it. Sort of fun) [ Ctrl + Shift + b ] or you can directly run it by pressing the function key “F5”. But “F5” will properly execute only if the code has no errors.
Lets see what result I got when I ran this program. I got 2 Camera’s in my laptop. So lets see if it lists them all. The following screenshots are my outputs.
I got 2 outputs !!!
1st Camera - HP Webcam
2nd Camera – USB camera
Awesome!!!!!!!!!!!!!!!!!!! AForge.NET got the list of camera’s connected to my computer.
Next tutorial is how to read video from a USB camera (a webcam in my case).