This is an example that demonstrates the use of FernImageDetector to detect an image as a marker.
{
bool flip_image = (image->origin?true:false);
if (flip_image) {
cvFlip(image);
image->origin = !image->origin;
}
cout << " [Ok]" << endl;
} else {
cout << " [Fail]" << endl;
}
double p[16];
}
if (image->nChannels == 3) {
cv::Mat img = cvarrToMat(image);
cv::cvtColor(img,
gray, CV_RGB2GRAY);
}
else {
}
vector<CvPoint2D64f> ipts;
vector<CvPoint3D64f> mpts;
if (test > 0.15 && mpts.size() > 4) {
}
if (flip_image) {
cvFlip(image);
image->origin = !image->origin;
}
}
int main(
int argc,
char *argv[])
{
try {
std::cout << "SampleMarkerlessDetector" << std::endl;
std::cout << "========================" << std::endl;
std::cout << std::endl;
std::cout << "Description:" << std::endl;
std::cout << " This is an example of how to use the 'FernImageDetector' and" << std::endl;
std::cout << " 'FernPoseEstimator' classes to detect and track an image and" << std::endl;
std::cout << " visualize it using 'GlutViewer'. The classification must first" << std::endl;
std::cout << " be trained with the SampleMarkerlessCreator sample and the" << std::endl;
std::cout << " resulting file passed as an argument to this sample." << std::endl;
std::cout << std::endl;
std::cout << " For optimal results, a high quality USB camera or a Firewire" << std::endl;
std::cout << " camera is necessary. It is also advised to calibrate the camera" << std::endl;
std::cout << " using the SampleCamCalib sample. It should be noted that the size" << std::endl;
std::cout << " of the trained image will affect the optimal distance for detection." << std::endl;
std::cout << std::endl;
std::cout << "Usage:" << std::endl;
std::cout <<
" " <<
filename <<
" filename [device]" << std::endl;
std::cout << std::endl;
std::cout << " filename the filename of classifier (.dat)" << std::endl;
std::cout << " device integer selecting device from enumeration list (default 0)" << std::endl;
std::cout << " highgui capture devices are prefered" << std::endl;
std::cout << std::endl;
std::cout << "Keyboard Shortcuts:" << std::endl;
std::cout << " q: quit" << std::endl;
std::cout << std::endl;
if (argc < 2) {
std::cout << "Filename not specified." << std::endl;
return 0;
}
std::string classifierFilename(argv[1]);
if (plugins.size() < 1) {
std::cout << "Could not find any capture plugins." << std::endl;
return 0;
}
std::cout << "Available Plugins: ";
std::cout << std::endl;
if (devices.size() < 1) {
std::cout << "Could not find any capture devices." << std::endl;
return 0;
}
if (argc > 2) {
selectedDevice = atoi(argv[2]);
}
if (selectedDevice >= (int)devices.size()) {
}
std::cout << "Enumerated Capture Devices:" << std::endl;
std::cout << std::endl;
std::string uniqueName = devices[selectedDevice].uniqueName();
if (cap) {
std::cout << "Loading classifier." << std::endl;
std::cout << "Loading classifier failed." << std::endl;
delete cap;
return 1;
}
std::stringstream settingsFilename;
settingsFilename << "camera_settings_" << uniqueName << ".xml";
std::cout << "Loading settings: " << settingsFilename.str() << std::endl;
}
std::stringstream title;
std::cout << "Saving settings: " << settingsFilename.str() << std::endl;
}
delete cap;
}
}
else {
std::cout << "Could not initialize the selected capture backend." << std::endl;
}
return 0;
}
catch (const std::exception &e) {
std::cout << "Exception: " << e.what() << endl;
}
catch (...) {
std::cout << "Exception: unknown" << std::endl;
}
}