16         const double scale = 0.2;
    18         glMultMatrixd(gl_mat);
    19         glColor3d(color[0], color[1], color[2]);
    21             glVertex3f(0.0, 0.0, -scale);
    22             glVertex3f(0.0, 0.0, scale);
    23             glVertex3f(0.0, -scale, 0.0);
    24             glVertex3f(0.0, scale, 0.0);
    25             glVertex3f(-scale, 0.0, 0.0);
    26             glVertex3f(scale, 0.0, 0.0);
    38     static IplImage *rgb = 0;
    39     static IplImage* bg_image = 0;
    41     bool flip_image = (image->origin?
true:
false);
    44         image->origin = !image->origin;
    55             cout<<
" [Fail]"<<endl;
    68             std::cout<<
"Using MultiMarker defined in mmarker.xml."<<std::endl;
    70             std::cout<<
"Couldn't load mmarker.xml. Using default 'SampleMultiMarker' setup."<<std::endl;
    92     if (sfm->
Update(image, 
false, 
true, 7.f, 15.f)) {
   105         std::map<int, SimpleSfM::Feature>::iterator iter;
   107         for(;iter != sfm->
container.end(); iter++) {
   109             if (iter->second.has_p3d) 
   123                     own_drawable_count++;
   131             if (iter->second.has_p3d) 
   145                     own_drawable_count++;
   150     if (image->nChannels == 1) cvCvtColor(image, rgb, CV_GRAY2RGB);
   151     else if (image->nChannels == 3) cvCopy(image, rgb);
   154     cvResize(rgb, bg_image);
   162         image->origin = !image->origin;
   178 int main(
int argc, 
char *argv[])
   183         filename = filename.substr(filename.find_last_of(
'\\') + 1);
   184         std::cout << 
"SamplePointcloud" << std::endl;
   185         std::cout << 
"================" << std::endl;
   186         std::cout << std::endl;
   187         std::cout << 
"Description:" << std::endl;
   188         std::cout << 
"  This example shows simple structure from motion approach that can be "<< std::endl;
   189         std::cout << 
"  used to track environment beyond an multimarker setup. To get this   "<< std::endl;
   190         std::cout << 
"  example work properly be sure to calibrate your camera and tune it   "<< std::endl;
   191         std::cout << 
"  to have fast framerate without motion blur.                          "<< std::endl;
   192         std::cout << std::endl;
   193         std::cout << 
"  There are two possible approaches Update() and UpdateRotationsOnly()."<< std::endl;
   194         std::cout << 
"  By default the Update() is used but you can easily uncomment the     "<< std::endl;
   195         std::cout << 
"  other one if needed."<< std::endl;
   196         std::cout << std::endl;
   197         std::cout << 
"Usage:" << std::endl;
   198         std::cout << 
"  " << filename << 
" [device]" << std::endl;
   199         std::cout << std::endl;
   200         std::cout << 
"    device    integer selecting device from enumeration list (default 0)" << std::endl;
   201         std::cout << 
"              highgui capture devices are prefered" << std::endl;
   202         std::cout << std::endl;
   203         std::cout << 
"Keyboard Shortcuts:" << std::endl;
   204         std::cout << 
"  r: reset" << std::endl;
   205         std::cout << 
"  q: quit" << std::endl;
   206         std::cout << std::endl;
   216         if (plugins.size() < 1) {
   217             std::cout << 
"Could not find any capture plugins." << std::endl;
   222         std::cout << 
"Available Plugins: ";
   224         std::cout << std::endl;
   228         if (devices.size() < 1) {
   229             std::cout << 
"Could not find any capture devices." << std::endl;
   236             selectedDevice = atoi(argv[1]);
   238         if (selectedDevice >= (
int)devices.size()) {
   243         std::cout << 
"Enumerated Capture Devices:" << std::endl;
   245         std::cout << std::endl;
   249         std::string uniqueName = devices[selectedDevice].uniqueName();
   254             std::stringstream settingsFilename;
   255             settingsFilename << 
"camera_settings_" << uniqueName << 
".xml";
   262                 std::cout << 
"Loading settings: " << settingsFilename.str() << std::endl;
   265             std::stringstream title;
   271                 std::cout << 
"Saving settings: " << settingsFilename.str() << std::endl;
   275             delete cap; cap = NULL;
   280             std::cout << 
"Could not initialize the selected capture backend." << std::endl;
   282         delete sfm; sfm = NULL;
   286     catch (
const std::exception &e) {
   287         std::cout << 
"Exception: " << e.what() << endl;
   290         std::cout << 
"Exception: unknown" << std::endl;
 
void GetOpenglProjectionMatrix(double proj_matrix[16], const int width, const int height, const float far_clip=1000.0f, const float near_clip=0.1f)
Get OpenGL matrix Generates the OpenGL projection matrix based on OpenCV intrinsic camera matrix K...
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 AddMarker(int marker_id, double edge_length, Pose &pose)
Add an marker to be a basis for tracking. It is good idea to call SetResetPoint after these...
virtual void stop()=0
Stops the camera capture. 
void SetScale(double s)
Set the suitable scale to be used. This affects quite much how the tracking behaves (when features ar...
void GetMatrixGL(double gl[16], bool mirror=true)
Get the transformation matrix representation of the Pose using OpenGL's transposed format...
virtual bool start()=0
Starts the camera capture. 
Simple structure from motion implementation using CameraEC , MarkerDetectorEC and TrackerFeaturesEC...
void Clear()
Clear all tracked features. 
void SetResetPoint()
Remember the current state and return here when the Reset is called. 
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. 
This file implements structure from motion. 
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...
std::map< int, Feature > container_triangulated
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...
bool AddMultiMarker(const char *fname, FILE_FORMAT format=FILE_FORMAT_XML)
Add MultiMarker from file as a basis for tracking. It is good idea to call SetResetPoint after these...
CameraEC * GetCamera()
Get the camera used internally. You need to use this to set correct camera calibration (see SamplePoi...
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. 
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...
std::vector< std::string > CapturePluginVector
Vector of strings. 
void SetColor(double _r=1, double _g=1, double _b=1)
void outputEnumeratedPlugins(CaptureFactory::CapturePluginVector &plugins)
void SetGlProjectionMatrix(double p[16])
void SetKeyCallback(int(*_keycallback)(int key))
Sets the keyboard callback function that will be called when keyboard is pressed. ...
OwnDrawable d_points[1000]
void SetGlModelviewMatrix(double p[16])
CaptureDeviceVector enumerateDevices(const std::string &captureType="")
Enumerate capture devices currently available. 
void Start(int argc, char **argv, int w, int h, float r=300.0)
int main(int argc, char *argv[])
bool Update(IplImage *image, bool assume_plane=true, bool triangulate=true, float reproj_err_limit=5.f, float triangulate_angle=15.f)
Update position assuming that camera is moving with 6-DOF. 
Pose representation derived from the Rotation class 
void DrawableAdd(Drawable *item)
CapturePluginVector enumeratePlugins()
Enumerate capture plugins currently available. 
void Draw(IplImage *rgba)
Draw debug information about the tracked features and detected markers. 
Pose * GetPose()
Get the estimated pose. 
std::stringstream calibrationFilename
void outputEnumeratedDevices(CaptureFactory::CaptureDeviceVector &devices, int selectedDevice)
void SetVideo(const IplImage *_image)
void SetScale(double _scale)
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. 
void SetTranslation(const CvMat *tra)
std::map< int, Feature > container
The map of all tracked features. 
void Reset(bool reset_also_triangulated=true)
Reset the situation back to the point it was when SetResetPoint was called. 
void videocallback(IplImage *image)
virtual bool saveSettings(std::string filename)
Save camera settings to a file.