20     bool flip_image = (image->origin?
true:
false);
    23         image->origin = !image->origin;
    30             cout << 
" [Ok]" << endl;
    33             cout << 
" [Fail]" << endl;
    39         gray = cv::Mat(image);
    42     if (image->nChannels == 3) {
    43         cv::Mat img = cvarrToMat(image);
    44         cv::cvtColor(img, 
gray, CV_RGB2GRAY);
    50     vector<CvPoint2D64f> ipts;
    51     vector<CvPoint3D64f> mpts;
    57     if (test > 0.15 && mpts.size() > 4) {
    68         image->origin = !image->origin;
    72 int main(
int argc, 
char *argv[])
    77         filename = filename.substr(filename.find_last_of(
'\\') + 1);
    78         std::cout << 
"SampleMarkerlessDetector" << std::endl;
    79         std::cout << 
"========================" << std::endl;
    80         std::cout << std::endl;
    81         std::cout << 
"Description:" << std::endl;
    82         std::cout << 
"  This is an example of how to use the 'FernImageDetector' and" << std::endl;
    83         std::cout << 
"  'FernPoseEstimator' classes to detect and track an image and" << std::endl;
    84         std::cout << 
"  visualize it using 'GlutViewer'. The classification must first" << std::endl;
    85         std::cout << 
"  be trained with the SampleMarkerlessCreator sample and the" << std::endl;
    86         std::cout << 
"  resulting file passed as an argument to this sample." << std::endl;
    87         std::cout << std::endl;
    88         std::cout << 
"  For optimal results, a high quality USB camera or a Firewire" << std::endl;
    89         std::cout << 
"  camera is necessary. It is also advised to calibrate the camera" << std::endl;
    90         std::cout << 
"  using the SampleCamCalib sample. It should be noted that the size" << std::endl;
    91         std::cout << 
"  of the trained image will affect the optimal distance for detection." << std::endl;
    92         std::cout << std::endl;
    93         std::cout << 
"Usage:" << std::endl;
    94         std::cout << 
"  " << filename << 
" filename [device]" << std::endl;
    95         std::cout << std::endl;
    96         std::cout << 
"    filename the filename of classifier (.dat)" << std::endl;
    97         std::cout << 
"    device   integer selecting device from enumeration list (default 0)" << std::endl;
    98         std::cout << 
"             highgui capture devices are prefered" << std::endl;
    99         std::cout << std::endl;
   100         std::cout << 
"Keyboard Shortcuts:" << std::endl;
   101         std::cout << 
"  q: quit" << std::endl;
   102         std::cout << std::endl;
   105             std::cout << 
"Filename not specified." << std::endl;
   108         std::string classifierFilename(argv[1]);
   116         if (plugins.size() < 1) {
   117             std::cout << 
"Could not find any capture plugins." << std::endl;
   122         std::cout << 
"Available Plugins: ";
   124         std::cout << std::endl;
   128         if (devices.size() < 1) {
   129             std::cout << 
"Could not find any capture devices." << std::endl;
   136             selectedDevice = atoi(argv[2]);
   138         if (selectedDevice >= (
int)devices.size()) {
   143         std::cout << 
"Enumerated Capture Devices:" << std::endl;
   145         std::cout << std::endl;
   149         std::string uniqueName = devices[selectedDevice].uniqueName();
   154             std::cout << 
"Loading classifier." << std::endl;
   156                 std::cout << 
"Loading classifier failed." << std::endl;
   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() 
This file implements a Fern-based image detector. 
Capture * createCapture(const CaptureDevice captureDevice)
Create Capture class. Transfers onwership to the caller. 
virtual void stop()=0
Stops the camera capture. 
FernImageDetector fernDetector(true)
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. 
CaptureDevice captureDevice()
The camera information associated to this capture object. 
Image detector based on a Fern classifier. 
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. 
void modelPoints(vector< CvPoint3D64f > &points, bool normalize=true)
std::vector< CaptureDevice > CaptureDeviceVector
Vector of CaptureDevices. 
FernPoseEstimator fernEstimator
This file implements a pose estimator for the Fern-based image detector. 
std::string captureType() const 
The type of capture backend. 
bool StartVideo(Capture *_cap, const char *_wintitle=0)
Start video input from given capture device. 
void setResolution(int width, int height)
std::vector< std::string > CapturePluginVector
Vector of strings. 
void videocallback(IplImage *image)
void outputEnumeratedPlugins(CaptureFactory::CapturePluginVector &plugins)
void SetGlProjectionMatrix(double p[16])
void imagePoints(vector< CvPoint2D64f > &points)
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)
bool setCalibration(const std::string &filename, int width, int height)
Pose representation derived from the Rotation class 
void DrawableAdd(Drawable *item)
std::stringstream calibrationFilename
CapturePluginVector enumeratePlugins()
Enumerate capture plugins currently available. 
bool read(const std::string &filename, const bool binary=true)
int main(int argc, char *argv[])
void outputEnumeratedDevices(CaptureFactory::CaptureDeviceVector &devices, int selectedDevice)
void SetScale(double _scale)
Capture interface that plugins must implement. 
void findFeatures(Mat &image, bool planeAssumption=true)
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. 
Pose estimation class for FernImageDetector. 
virtual bool saveSettings(std::string filename)
Save camera settings to a file. 
void calculateFromPointCorrespondences(ModelPointVector &mpts, ImagePointVector &ipts)