Go to the documentation of this file.00001
00034
00035
00036 #include <iostream>
00037 #include <fstream>
00038 #include <vector>
00039 #include <string>
00040 #include <opencv/cv.h>
00041 #include <opencv/highgui.h>
00042
00043 #include "../ObjectModel.h"
00044
00045 #include "ros/ros.h"
00046 #include "DUtils.h"
00047 #include "DUtilsCV.h"
00048
00049 using namespace std;
00050
00051
00052
00053 int main(int argc, char *argv[])
00054 {
00055 ros::init(argc, argv, "testModel");
00056
00057 if(argc < 1)
00058 {
00059 cout << "Usage: " << argv[0] << " <model dir>" << endl;
00060 return 0;
00061 }
00062
00063 string model_dir = argv[1];
00064
00065 cout << "-- Creating test directory" << endl;
00066
00067 string test_dir = model_dir + "/test";
00068 DUtils::FileFunctions::MkDir(test_dir.c_str());
00069
00070 cout << "-- Loading model" << endl;
00071
00072 ObjectModel model;
00073 model.loadDirectory(model_dir, true);
00074
00075 vector<ObjectModel::Face>::const_iterator fit;
00076 for(fit = model.Faces.begin(); fit != model.Faces.end(); ++fit)
00077 {
00078 const int idx = fit - model.Faces.begin();
00079
00080 cv::Mat cTo = DUtilsCV::Transformations::composeRt(fit->cRo, fit->cto);
00081
00082 cout << "-- Copying image " << idx << endl;
00083 cv::Mat image, aux;
00084 if(fit->image.channels() == 3)
00085 {
00086 cv::cvtColor(fit->image, aux, CV_RGB2GRAY);
00087 cv::cvtColor(aux, image, CV_GRAY2RGB);
00088 }else
00089 {
00090 cv::cvtColor(fit->image, image, CV_GRAY2RGB);
00091 }
00092
00093 cout << "-- Drawing image " << idx << endl;
00094
00095 DUtilsCV::Drawing::drawKeyPoints(image, fit->surf.keys);
00096 model.getVisualizationModel().draw(image, cTo, fit->A);
00097
00098 char buffer[512];
00099 sprintf(buffer, "%s/test_%03d.png", test_dir.c_str(), idx);
00100 cv::imwrite(buffer, image);
00101 }
00102
00103 cout << "Done. Results saved in " << test_dir << endl;
00104
00105 }
00106
00107
00108
00109