First off, let me begin by saying I absolutely love OpenCV. The guys that designed this gem really knew what they were doing. I’ve written several articles showing how to create applications using OpenCV and C#. However, I’m still getting a ton of emails from readers that are still having issues when working with OpenCV and with my schedule, it’s hard to keep track of all of them. And that got me thinking. What would it take to create my own, easier, simpler version of OpenCV using nothing but C#? There wouldn’t be any wrappers or any need for anything that Windows and the .NET framework don’t already provide you. So, I set out to find out.
Before I started writing any code, I did some digging around on the interwebernets to see how other people were doing similar stuff. I began with learning how to connect to a standard USB webcam and capture the video stream from it. Pretty much every article I read talked about using the AVI Capture DLL (avicap32.dll) that comes built into Microsoft Windows. (If you’re curious, you can locate this file in your Windows > System32 folder.) Along with the articles that recommended using avicap32.dll, every single one of those articles had downloads for the same exact source code.
Ok. Cool. I decided to download the code and see what it was all about. After about 2 minutes of tinkering with the examples, I was able to get the application working with my cheap-o USB webcam. However, the performance was pitiful. The video ran like a dead dog, displaying a frame rate of like 5 frames per second if that. So, the video was too slow and had too much of a lag to be of any use for real-time processing like most of us wish to do.
Surely there was something I could do to improve the performance? When I started digging deeper into the code, I noticed a HUGE performance issue. The application was waiting for a set interval and grabbing individual frames from the camera. Then, to make things worse, it was copying those frames onto the Windows clipboard and then turning around and getting the frames from the clipboard and returning thumbnail images back to the Windows form control. Ummm??? WTF?!?!? How could anyone think that was a good idea? I thought maybe it was just that way in the source code example I downloaded. So, I downloaded 4 or 5 more examples from other websites. Each of the examples had their own naming conventions and way of doing things. But, every one of those examples did the same exact thing.
Well, this wasn’t acceptable for what I have in mind. So, I did some playing and rewrote the entire thing from scratch. I’m still using the built-in avicap32.dll, but I did away with all of the clipboard crap, worthless finalizers, and junk that just didn’t need to be there. I have managed to slim down my version of this application to a reduced code base that is less than 40% of the size of the examples I messed around with. I even set it up so that you can pass a handler for your picture box control directly to the API. This cuts out all of the middle-man work and renders the final output directly on your screen. My new version is also 10 times faster than the original. In fact, it’s all real-time now and has zero lag in the video stream.
Capturing video from a camera and displaying it in a Windows form is all I’ve had time to do so far. But, I don’t think it’s going to take me too long to add in many of the features that OpenCV has. I have done a lot of work in this field in the past. So, I already know many of the trade-secrets and how they work. I’m going to mess around with this new framework in between my real work and will hopefully have something usable within the next few weeks. Now, I’m not saying it’s going to have all of the cool stuff that OpenCV has, but I will try to include as much as possible. When I get something ready, I’ll post it on here for you guys to checkout. Heck, I’ll even setup an entirely new website for the project so that I’ll have a place for documentation and discussions solely for the framework. At some point, I’ll even write versions for Java, C++, and Python as well.
In the mean time, I want to invite you guys to help me come up with a name for the framework. Also, share with me any ideas that you may have that could make the framework easier to work with. Is there anything specific about OpenCV that just irritates you? Are there any things that my new framework could do differently to make your lives easier? I already have several ideas that I think could be a major improvement over the current technology. But, I’d still like to see what thoughts you have. I’ll be sure to include recognition both on the new website and inside the framework for those of you that contribute.
While you’re at it, be sure to also think about ideas for GUI tools that could utilize this framework. I would like to create an interface that would allow you to pick from a list how you want the framework to perform and it will just do it. If things work out the way I have in mind, you wouldn’t have to write a single line of code to get the same functionality that many of you are already asking for today. But, for the rest of you that have extremely specific needs for this kind of technology, don’t fret. I still plan on helping you with your current OpenCV applications as well.
So, until next time, happy coding!