16     static IplImage *rgba;
    17     bool flip_image = (image->origin?
true:
false);
    20         image->origin = !image->origin;
    29             cam.
SetRes(image->width, image->height);
    30             cout<<
" [Fail]"<<endl;
    35         for (
int i=0; i<32; i++) {
    47     marker_detector.
Detect(image, &cam, 
true, 
true);
    49     for (
size_t i=0; i<marker_detector.
markers->size(); i++) {
    55         int id = (*(marker_detector.
markers))[i].GetId();
    56         double r = 1.0 - double(
id+1)/32.0;
    57         double g = 1.0 - double(
id*3%32+1)/32.0;
    58         double b = 1.0 - double(
id*7%32+1)/32.0;
    66         image->origin = !image->origin;
    70 int main(
int argc, 
char *argv[])
    75         filename = filename.substr(filename.find_last_of(
'\\') + 1);
    76         std::cout << 
"SampleMarkerDetector" << std::endl;
    77         std::cout << 
"====================" << std::endl;
    78         std::cout << std::endl;
    79         std::cout << 
"Description:" << std::endl;
    80         std::cout << 
"  This is an example of how to detect 'MarkerData' markers using" << std::endl;
    81         std::cout << 
"  'MarkerDetector' and visualize them using 'GlutViewer'. In the" << std::endl;
    82         std::cout << 
"  SampleMarkerDetector window, various debug information is shown" << std::endl;
    83         std::cout << 
"  about the detected markers. The coordinate axes and a virtual cube" << std::endl;
    84         std::cout << 
"  are superimposed onto the markers to visualize the detected pose." << std::endl;
    85         std::cout << 
"  For each marker, a small image of the marker content is displayed" << std::endl;
    86         std::cout << 
"  at the origin and the marker number is displayed at one of the" << std::endl;
    87         std::cout << 
"  corners. At the opposing corner, the error estimation percentages" << std::endl;
    88         std::cout << 
"  'MARGIN_ERROR' and 'DECODE_ERROR' (red) or 'TRACK_ERROR' (dark red)" << std::endl;
    89         std::cout << 
"  are displayed." << std::endl;
    90         std::cout << std::endl;
    91         std::cout << 
"  In the AR window, squares are drawn over the marker positions using" << std::endl;
    92         std::cout << 
"  OpenGL. In the VR window, the squares are drawn with respect to the" << std::endl;
    93         std::cout << 
"  camera coordinate frame. The viewpoint can be modified by dragging" << std::endl;
    94         std::cout << 
"  with the left and right mouse buttons." << std::endl;
    95         std::cout << std::endl;
    96         std::cout << 
"Usage:" << std::endl;
    97         std::cout << 
"  " << filename << 
" [device|filename]" << std::endl;
    98         std::cout << std::endl;
    99         std::cout << 
"    device    integer selecting device from enumeration list (default 0)" << std::endl;
   100         std::cout << 
"              highgui capture devices are prefered" << std::endl;
   101         std::cout << 
"    filename  string specifying a media file as input" << std::endl;
   102         std::cout << std::endl;
   103         std::cout << 
"Keyboard Shortcuts:" << std::endl;
   104         std::cout << 
"  q: quit" << std::endl;
   105         std::cout << std::endl;
   113         std::string uniqueName;
   114         if ((argc > 1) && (!isdigit(argv[1][0]))) {
   123             if (plugins.size() < 1) {
   124                 std::cout << 
"Could not find any capture plugins." << std::endl;
   129             std::cout << 
"Available Plugins: ";
   131             std::cout << std::endl;
   135             if (devices.size() < 1) {
   136                 std::cout << 
"Could not find any capture devices." << std::endl;
   143                 selectedDevice = atoi(argv[1]);
   145             if (selectedDevice >= (
int)devices.size()) {
   150             std::cout << 
"Enumerated Capture Devices:" << std::endl;
   152             std::cout << std::endl;
   156             uniqueName = devices[selectedDevice].uniqueName();
   162             std::stringstream settingsFilename;
   163             settingsFilename << 
"camera_settings_" << uniqueName << 
".xml";
   170                 std::cout << 
"Loading settings: " << settingsFilename.str() << std::endl;
   173             std::stringstream title;
   179                 std::cout << 
"Saving settings: " << settingsFilename.str() << std::endl;
   188             std::cout << 
"Could not initialize the selected capture backend." << std::endl;
   193     catch (
const std::exception &e) {
   194         std::cout << 
"Exception: " << e.what() << endl;
   197         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. 
virtual void stop()=0
Stops the camera capture. 
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. 
void SetMarkerSize(double _edge_length=1, int _res=5, double _margin=2)
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. 
This file implements a generic marker detector. 
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...
std::vector< CaptureDevice > CaptureDeviceVector
Vector of CaptureDevices. 
Simple Camera class for calculating distortions, orientation or projections with pre-calibrated camer...
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< M, Eigen::aligned_allocator< M > > * markers
std::vector< std::string > CapturePluginVector
Vector of strings. 
int main(int argc, char *argv[])
void SetColor(double _r=1, double _g=1, double _b=1)
CaptureDevice holder for camera information. 
void outputEnumeratedPlugins(CaptureFactory::CapturePluginVector &plugins)
MarkerDetector for detecting markers of type M 
void SetGlProjectionMatrix(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)
Pose representation derived from the Rotation class 
void DrawableAdd(Drawable *item)
CapturePluginVector enumeratePlugins()
Enumerate capture plugins currently available. 
void videocallback(IplImage *image)
MarkerDetector< MarkerData > marker_detector
std::stringstream calibrationFilename
void outputEnumeratedDevices(CaptureFactory::CaptureDeviceVector &devices, int selectedDevice)
void SetScale(double _scale)
Capture interface that plugins must implement. 
int Detect(IplImage *image, Camera *cam, bool track=false, bool visualize=false, double max_new_marker_error=0.08, double max_track_error=0.2, LabelingMethod labeling_method=CVSEQ, bool update_pose=true)
Detect Marker 's from image 
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.