8     static IplImage *img_gray=NULL;
    11     if (img_gray == NULL) {
    15     if (image->nChannels > 1) { 
    16         cvCvtColor(image, img_gray, CV_RGB2GRAY);
    18         cvCopy(image, img_gray);
    23 int main(
int argc, 
char *argv[])
    28         filename = filename.substr(filename.find_last_of(
'\\') + 1);
    29         std::cout << 
"SampleCvTestbed" << std::endl;
    30         std::cout << 
"===============" << std::endl;
    31         std::cout << std::endl;
    32         std::cout << 
"Description:" << std::endl;
    33         std::cout << 
"  This is an example of how to use the 'CvTestbed', 'CaptureFactory' and" << std::endl;
    34         std::cout << 
"  'Capture' classes. The 'CaptureFactory' can create 'Capture' objects" << std::endl;
    35         std::cout << 
"  from many different backends (see SampleCvTestbed.cpp). You can also" << std::endl;
    36         std::cout << 
"  show/hide the 1st ten images created using 'CvTestbed' using the number" << std::endl;
    37         std::cout << 
"  keys. In this example you can use key '0' to show/hide a grayscale" << std::endl;
    38         std::cout << 
"  version of the captured image." << std::endl;
    39         std::cout << std::endl;
    40         std::cout << 
"Usage:" << std::endl;
    41         std::cout << 
"  " << filename << 
" [device]" << std::endl;
    42         std::cout << std::endl;
    43         std::cout << 
"    device    integer selecting device from enumeration list (default 0)" << std::endl;
    44         std::cout << 
"              highgui capture devices are prefered" << std::endl;
    45         std::cout << std::endl;
    46         std::cout << 
"Keyboard Shortcuts:" << std::endl;
    47         std::cout << 
"  0: show/hide grayscale image" << std::endl;
    48         std::cout << 
"  q: quit" << std::endl;
    49         std::cout << std::endl;
    56         if (plugins.size() < 1) {
    57             std::cout << 
"Could not find any capture plugins." << std::endl;
    62         std::cout << 
"Available Plugins: ";
    64         std::cout << std::endl;
    68         if (devices.size() < 1) {
    69             std::cout << 
"Could not find any capture devices." << std::endl;
    76             selectedDevice = atoi(argv[1]);
    78         if (selectedDevice >= (
int)devices.size()) {
    83         std::cout << 
"Enumerated Capture Devices:" << std::endl;
    85         std::cout << std::endl;
    89         std::string uniqueName = devices[selectedDevice].uniqueName();
    94             std::stringstream settingsFilename;
    95             settingsFilename << 
"camera_settings_" << uniqueName << 
".xml";
   101                 std::cout << 
"Loading settings: " << settingsFilename.str() << std::endl;
   104             std::stringstream title;
   110                 std::cout << 
"Saving settings: " << settingsFilename.str() << std::endl;
   119             std::cout << 
"Could not initialize the selected capture backend." << std::endl;
   124     catch (
const std::exception &e) {
   125         std::cout << 
"Exception: " << e.what() << endl;
   128         std::cout << 
"Exception: unknown" << std::endl;
 
static CvTestbed & Instance()
The one and only instance of CvTestbed is accessed using CvTestbed::Instance() 
Capture * createCapture(const CaptureDevice captureDevice)
Create Capture class. Transfers onwership to the caller. 
virtual void stop()=0
Stops the camera capture. 
virtual bool start()=0
Starts the camera capture. 
int main(int argc, char *argv[])
CaptureDevice captureDevice()
The camera information associated to this capture object. 
void SetVideoCallback(void(*_videocallback)(IplImage *image))
Set the videocallback function that will be called for every frame. 
static CaptureFactory * instance()
The singleton instance of CaptureFactory. 
IplImage * CreateImageWithProto(const char *title, IplImage *proto, int depth=0, int channels=0)
Creates an image based on the given prototype and stores it with a given 'title' (see CvTestbed::SetI...
std::vector< CaptureDevice > CaptureDeviceVector
Vector of CaptureDevices. 
std::string captureType() const 
The type of capture backend. 
bool StartVideo(Capture *_cap, const char *_wintitle=0)
Start video input from given capture device. 
std::vector< std::string > CapturePluginVector
Vector of strings. 
void outputEnumeratedPlugins(CaptureFactory::CapturePluginVector &plugins)
CaptureDeviceVector enumerateDevices(const std::string &captureType="")
Enumerate capture devices currently available. 
CapturePluginVector enumeratePlugins()
Enumerate capture plugins currently available. 
void outputEnumeratedDevices(CaptureFactory::CaptureDeviceVector &devices, int selectedDevice)
Capture interface that plugins must implement. 
virtual bool loadSettings(std::string filename)
Load camera settings from a file. 
int defaultDevice(CaptureFactory::CaptureDeviceVector &devices)
virtual void setResolution(const unsigned long xResolution, const unsigned long yResolution)
Set the resolution. 
void videocallback(IplImage *image)
virtual bool saveSettings(std::string filename)
Save camera settings to a file.