23         x = img_gray->width / 2;
    24         y = img_gray->height / 2;
    25         tracker_psa.
Track(img_gray); 
    27     tracker_psa.
Track(img_gray);
    29     cvCircle(image, cvPoint(
int(x), 
int(y)), 10, CV_RGB(255,0,0));
    34     static double x, 
y, 
r;
    37         x = img_gray->width / 2;
    38         y = img_gray->height / 2;
    40         tracker_psa_rot.
Track(img_gray); 
    42     tracker_psa_rot.
Track(img_gray);
    44     r += tracker_psa_rot.
rotd;
    45     cvCircle(image, cvPoint(
int(x), 
int(y)), 15, CV_RGB(255,0,0));
    46     double r_rad = r*3.1415926535/180;
    47     cvLine(image, cvPoint(
int(x), 
int(y)), cvPoint(
int(x-sin(r_rad)*15), 
int(y+cos(r_rad)*15)), CV_RGB(255,0,0));
    55         x = img_gray->width / 2;
    56         y = img_gray->height / 2;
    57         tracker_stat.
Track(img_gray); 
    59     tracker_stat.
Track(img_gray);
    61     cvCircle(image, cvPoint(
int(x), 
int(y)), 10, CV_RGB(0,255,0));
    66     static double x, 
y, 
r;
    69         x = img_gray->width / 2;
    70         y = img_gray->height / 2;
    72         tracker_stat_rot.
Track(img_gray); 
    74     tracker_stat_rot.
Track(img_gray);
    76     r += tracker_stat_rot.
rotd;
    77     cvCircle(image, cvPoint(
int(x), 
int(y)), 15, CV_RGB(0,255,0));
    78     double r_rad = r*3.1415926535/180;
    79     cvLine(image, cvPoint(
int(x), 
int(y)), cvPoint(
int(x-sin(r_rad)*15), 
int(y+cos(r_rad)*15)), CV_RGB(0,255,0));
    86         tracker_features.
Reset();
    88     tracker_features.
Purge();
    89     tracker_features.
Track(img_gray);
    92             cvPoint(
int(tracker_features.
features[i].x), 
int(tracker_features.
features[i].y)), 2, 
    93             CV_RGB(tracker_features.
ids[i]%255,(tracker_features.
ids[i]*7)%255,(tracker_features.
ids[i]*11)%255));
   107     "No tracker - Press any key to change",
   119     static IplImage *img_gray=NULL;
   120     static bool init=
true;
   130             cam.
SetRes(image->width, image->height);
   131             cout<<
" [Fail]"<<endl;
   134     if (image->nChannels == 1) cvCopy(image, img_gray);
   135     else cvCvtColor(image, img_gray, CV_RGB2GRAY);
   138     cvPutText(image, tracker_names[
tracker], cvPoint(3, image->height - 20), &
font, CV_RGB(255, 255, 255));
   142     if ((key == 
'r') || (key == 
't')) {
   146     else if ((key == 
'n') || (key == 
' ')){
   154 int main(
int argc, 
char *argv[])
   159         filename = filename.substr(filename.find_last_of(
'\\') + 1);
   160         std::cout << 
"SampleTrack" << std::endl;
   161         std::cout << 
"===========" << std::endl;
   162         std::cout << std::endl;
   163         std::cout << 
"Description:" << std::endl;
   164         std::cout << 
"  This is an example of how to use the 'TrackerPsa', 'TrackerPsaRot'," << std::endl;
   165         std::cout << 
"  'TrackerFeatures', 'TrackerStat' and 'TrackerStatRot' classes to" << std::endl;
   166         std::cout << 
"  track the optical flow of the video." << std::endl;
   167         std::cout << std::endl;
   168         std::cout << 
"Usage:" << std::endl;
   169         std::cout << 
"  " << filename << 
" [device]" << std::endl;
   170         std::cout << std::endl;
   171         std::cout << 
"    device    integer selecting device from enumeration list (default 0)" << std::endl;
   172         std::cout << 
"              highgui capture devices are prefered" << std::endl;
   173         std::cout << std::endl;
   174         std::cout << 
"Keyboard Shortcuts:" << std::endl;
   175         std::cout << 
"  r,t: reset tracker" << std::endl;
   176         std::cout << 
"  n,space: cycle through tracking algorithms" << std::endl;
   177         std::cout << 
"  q: quit" << std::endl;
   178         std::cout << std::endl;
   181         cvInitFont(&
font, CV_FONT_HERSHEY_PLAIN, 1.0, 1.0);
   189         if (plugins.size() < 1) {
   190             std::cout << 
"Could not find any capture plugins." << std::endl;
   195         std::cout << 
"Available Plugins: ";
   197         std::cout << std::endl;
   201         if (devices.size() < 1) {
   202             std::cout << 
"Could not find any capture devices." << std::endl;
   209             selectedDevice = atoi(argv[1]);
   211         if (selectedDevice >= (
int)devices.size()) {
   216         std::cout << 
"Enumerated Capture Devices:" << std::endl;
   218         std::cout << std::endl;
   222         std::string uniqueName = devices[selectedDevice].uniqueName();
   227             std::stringstream settingsFilename;
   228             settingsFilename << 
"camera_settings_" << uniqueName << 
".xml";
   235                 std::cout << 
"Loading settings: " << settingsFilename.str() << std::endl;
   238             std::stringstream title;
   244                 std::cout << 
"Saving settings: " << settingsFilename.str() << std::endl;
   253             std::cout << 
"Could not initialize the selected capture backend." << std::endl;
   258     catch (
const std::exception &e) {
   259         std::cout << 
"Exception: " << e.what() << endl;
   262         std::cout << 
"Exception: unknown" << std::endl;
 
void videocallback(IplImage *image)
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. 
TrackerPsa implements a very simple PSA tracker 
virtual void stop()=0
Stops the camera capture. 
CvPoint2D32f * features
Track result: current features 
void trackers(IplImage *image, IplImage *img_gray)
double Track(IplImage *img)
Track features. 
This file implements a camera used for projecting points and computing homographies. 
TrackerPsaRot implements a slightly extended version of a TrackerPsa which can also detect sideways r...
void track_none(IplImage *image, IplImage *img_gray)
virtual bool start()=0
Starts the camera capture. 
void track_psa(IplImage *image, IplImage *img_gray)
CaptureDevice captureDevice()
The camera information associated to this capture object. 
TrackerStatRot implements a slightly extended version of TrackerStat which can also detect sideways r...
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...
void SetRes(int _x_res, int _y_res)
If we have no calibration file we can still adjust the default calibration to current resolution...
void track_psa_rot(IplImage *image, IplImage *img_gray)
void track_features(IplImage *image, IplImage *img_gray)
double Track(IplImage *img)
Track using PSA with rotation. 
TFSIMD_FORCE_INLINE const tfScalar & y() const 
std::stringstream calibrationFilename
std::vector< CaptureDevice > CaptureDeviceVector
Vector of CaptureDevices. 
Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camer...
int Purge()
Purge features that are considerably closer than the defined min_distance. 
std::string captureType() const 
The type of capture backend. 
void track_stat(IplImage *image, IplImage *img_gray)
bool StartVideo(Capture *_cap, const char *_wintitle=0)
Start video input from given capture device. 
bool SetCalib(const char *calibfile, int _x_res, int _y_res, FILE_FORMAT format=FILE_FORMAT_DEFAULT)
Set the calibration file and the current resolution for which the calibration is adjusted to...
virtual void Compensate(double *x, double *y)
std::vector< std::string > CapturePluginVector
Vector of strings. 
void outputEnumeratedPlugins(CaptureFactory::CapturePluginVector &plugins)
void SetKeyCallback(int(*_keycallback)(int key))
Sets the keyboard callback function that will be called when keyboard is pressed. ...
This file implements a statistical tracker. 
This file implements a PSA tracker. 
CaptureDeviceVector enumerateDevices(const std::string &captureType="")
Enumerate capture devices currently available. 
This file implements a feature tracker. 
double Track(IplImage *img)
Translation tracker (the simplest possible) 
double rotd
Track result rotation in degrees 
virtual void Compensate(double *x, double *y)
TFSIMD_FORCE_INLINE const tfScalar & x() const 
CapturePluginVector enumeratePlugins()
Enumerate capture plugins currently available. 
int feature_count
Track result: count of current features 
TrackerFeatures tracks features using OpenCV's cvGoodFeaturesToTrack and cvCalcOpticalFlowPyrLK ...
void outputEnumeratedDevices(CaptureFactory::CaptureDeviceVector &devices, int selectedDevice)
int * ids
Track result: ID:s for current features 
virtual void Compensate(double *x, double *y)
int main(int argc, char *argv[])
Capture interface that plugins must implement. 
double Track(IplImage *img)
Translation + rotation tracker. 
virtual bool loadSettings(std::string filename)
Load camera settings from a file. 
int defaultDevice(CaptureFactory::CaptureDeviceVector &devices)
TrackerStat deduces the optical flow based on tracked features using Seppo Valli's statistical tracki...
virtual void setResolution(const unsigned long xResolution, const unsigned long yResolution)
Set the resolution. 
double rotd
Track result rotation in degrees 
void track_stat_rot(IplImage *image, IplImage *img_gray)
virtual bool saveSettings(std::string filename)
Save camera settings to a file. 
char tracker_names[nof_trackers][64]
double Track(IplImage *img)
Track using PSA. 
virtual void Compensate(double *x, double *y)