For the last couple weeks I’ve been struggling with getting camera capture inside a desktop application (yes – I lower myself to do desktop development occasionally). The problem I’m finding is that API documentation and especially sample availability for things like DShow and Windows Image Acquisition (WIA) are pretty poor and there seem to be no reasonable, comprehensize samples on how to use any of it. Occasionally you find something on sites like CodeProject, but IMO those projects tend to suck. The authors typically “solve” a specific problem by writing code tightly coupled to the problem they’re solving, so the code is very rarely reusable or extensible, and the quality usually is lacking as well.
Well today I finished up a general library and test harness for WIA. It’s too soon to tell if we’ll actually use it in the application I’m working on, since it’s missing a lot of capabilities that DShow will likely be better for, but to save a little headache in the developer community, I’m making it shared source (under our typical MIT x11 license). It provides a simple object model for seeing what cameras you have, displaying live video from them and grabbing frames. The test harness generates a TabControl with a page for each camera you have plugged in. If you add or remove a camera while the app is running, tabs are added or removed.
Most importantly I designed the clas library for general use. It can be dropped into any project and consumed for camera control without a bunch of rewrite, and while I’m not going to say it’s bug free, I at least tested it though several scenarios and let it run for a fairly long time without it puking (which is more than I can say about pretty much anything else I found).
Below is the object model and a screen shot of the test app.
Download the source code here (Updated 8/16/13).