9     static IplImage *img_grad = NULL;
    10     static IplImage *img_gray = NULL;
    11     static IplImage *img_ver = NULL;
    12     static IplImage *img_hor = NULL;
    13     static IplImage *img_canny = NULL;
    18     if (img_gray == NULL) {
    26         img_canny->origin = img_ver->origin = img_hor->origin = image->origin;
    28     if (image->nChannels > 1) { 
    29         cvCvtColor(image, img_gray, CV_RGB2GRAY);
    31         cvCopy(image, img_gray);
    43     integ.
GetSubimage(cvRect(0,0,image->width,image->height), img_ver);
    44     integ.
GetSubimage(cvRect(0,0,image->width,image->height), img_hor);
    45     for (
int y=1; 
y<image->height; 
y++) {
    47                cvPoint(
int(cvGet2D(img_ver, 
y-1, 0).val[0]), 
y-1), 
    48                cvPoint(
int(cvGet2D(img_ver, 
y, 0).val[0]), 
y), 
    51     for (
int x=1; 
x<image->width; 
x++) {
    53                cvPoint(
x-1, 
int(cvGet2D(img_hor, 0, 
x-1).val[0])), 
    54                cvPoint(
x, 
int(cvGet2D(img_hor, 0, 
x).val[0])), 
    76     static int t1=64, t2=192;
    77     cvCreateTrackbar(
"t1", 
"Gradient", &t1, 255, NULL);
    78     cvCreateTrackbar(
"t2", 
"Gradient", &t2, 255, NULL);
    79     cvCanny(img_gray, img_canny, t1, t2);
    81     for (r.y=0; r.y<img_canny->height-4; r.y++) {
    82         for (r.x=0; r.x<img_canny->width-4; r.x++) {
    83             if (img_canny->imageData[r.y*img_canny->widthStep+r.x]) {
    86                 cvLine(img_grad, cvPoint(r.x+2,r.y+2), cvPoint(r.x+2+
int(dirx),r.y+2+
int(diry)), CV_RGB(0,0,255));
    87                 cvLine(img_grad, cvPoint(r.x+2,r.y+2), cvPoint(r.x+2+
int(-diry),r.y+2+
int(+dirx)), CV_RGB(255,0,0));
    88                 cvLine(img_grad, cvPoint(r.x+2,r.y+2), cvPoint(r.x+2+
int(+diry),r.y+2+
int(-dirx)), CV_RGB(255,0,0));
    97 int main(
int argc, 
char *argv[])
   102         filename = filename.substr(filename.find_last_of(
'\\') + 1);
   103         std::cout << 
"SampleIntegralImage" << std::endl;
   104         std::cout << 
"===================" << std::endl;
   105         std::cout << std::endl;
   106         std::cout << 
"Description:" << std::endl;
   107         std::cout << 
"  This is an example of how to use the 'IntegralImage' and" << std::endl;
   108         std::cout << 
"  'IntegralGradient' classes. The vertical (green) and horizontal (red)" << std::endl;
   109         std::cout << 
"  whole image projections are computed using 'IntegralImage::GetSubimage'" << std::endl;
   110         std::cout << 
"  and shown in the SampleIntegralImage window. The gradients of the" << std::endl;
   111         std::cout << 
"  image edges are shown in the Gradient window. The edges are detected" << std::endl;
   112         std::cout << 
"  using the Canny edge detector where t1 and t2 are parameters for the" << std::endl;
   113         std::cout << 
"  Canny algorithm. The gradients are drawn in red and their local normals" << std::endl;
   114         std::cout << 
"  are drawn in blue." << std::endl;
   115         std::cout << std::endl;
   116         std::cout << 
"Usage:" << std::endl;
   117         std::cout << 
"  " << filename << 
" [device]" << std::endl;
   118         std::cout << std::endl;
   119         std::cout << 
"    device    integer selecting device from enumeration list (default 0)" << std::endl;
   120         std::cout << 
"              highgui capture devices are prefered" << std::endl;
   121         std::cout << std::endl;
   122         std::cout << 
"Keyboard Shortcuts:" << std::endl;
   123         std::cout << 
"  0: show/hide gradient image" << std::endl;
   124         std::cout << 
"  1: show/hide grayscale image" << std::endl;
   125         std::cout << 
"  2: show/hide vertical image" << std::endl;
   126         std::cout << 
"  3: show/hide horizontal image" << std::endl;
   127         std::cout << 
"  4: show/hide canny image" << std::endl;
   128         std::cout << 
"  q: quit" << std::endl;
   129         std::cout << std::endl;
   136         if (plugins.size() < 1) {
   137             std::cout << 
"Could not find any capture plugins." << std::endl;
   142         std::cout << 
"Available Plugins: ";
   144         std::cout << std::endl;
   148         if (devices.size() < 1) {
   149             std::cout << 
"Could not find any capture devices." << std::endl;
   156             selectedDevice = atoi(argv[1]);
   158         if (selectedDevice >= (
int)devices.size()) {
   163         std::cout << 
"Enumerated Capture Devices:" << std::endl;
   165         std::cout << std::endl;
   169         std::string uniqueName = devices[selectedDevice].uniqueName();
   174             std::stringstream settingsFilename;
   175             settingsFilename << 
"camera_settings_" << uniqueName << 
".xml";
   181                 std::cout << 
"Loading settings: " << settingsFilename.str() << std::endl;
   184             std::stringstream title;
   190                 std::cout << 
"Saving settings: " << settingsFilename.str() << std::endl;
   199             std::cout << 
"Could not initialize the selected capture backend." << std::endl;
   204     catch (
const std::exception &e) {
   205         std::cout << 
"Exception: " << e.what() << endl;
   208         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. 
void Update(IplImage *gray)
Update integral image for the given image. 
This file implements integral image and integral gradient computations. 
virtual void stop()=0
Stops the camera capture. 
virtual bool start()=0
Starts the camera capture. 
IntegralImage is used for calculating rectangular image sums and averages rapidly ...
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 * CreateImage(const char *title, CvSize size, int depth, int channels)
Creates an image with given size, depth and channels and stores it with a given 'title' (see CvTestbe...
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...
TFSIMD_FORCE_INLINE const tfScalar & y() const 
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)
void GetAveGradient(CvRect &rect, double *dirx, double *diry)
Calculate the average gradient for the given rectangular area in the image. 
CaptureDeviceVector enumerateDevices(const std::string &captureType="")
Enumerate capture devices currently available. 
void Update(IplImage *gray)
Update intermediate images for calculating the gradients to the given image. 
TFSIMD_FORCE_INLINE const tfScalar & x() const 
CapturePluginVector enumeratePlugins()
Enumerate capture plugins currently available. 
int main(int argc, char *argv[])
IntegralGradient is used for calculating rectangular image gradients rapidly 
void outputEnumeratedDevices(CaptureFactory::CaptureDeviceVector &devices, int selectedDevice)
bool ToggleImageVisible(size_t index, int flags=1)
Toggle the visibility of the stored image. 
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. 
virtual bool saveSettings(std::string filename)
Save camera settings to a file. 
void GetSubimage(const CvRect &rect, IplImage *sub)
Get a sub-image using integral image representation. 
void videocallback(IplImage *image)