Go to the documentation of this file.00001
00043 #include "ros/ros.h"
00044
00045 #include <iostream>
00046 #include <iomanip>
00047 #include <vector>
00048 #include <string>
00049 #include <sstream>
00050
00051 #include <opencv/cv.h>
00052 #include <opencv/highgui.h>
00053
00054 #include "../MetaFile.h"
00055 #include "../ObjectModel.h"
00056
00057 #include "DUtils.h"
00058 #include "DUtilsCV.h"
00059 #include "DVision.h"
00060
00061 using namespace std;
00062
00063
00064
00065 int main(int argc, char *argv[])
00066 {
00067 ros::init(argc, argv, "showModel");
00068
00069 if(argc < 2)
00070 {
00071 ROS_WARN("Usage: %s <model dir> [ z v1 v2 v3 a <output img> ]", argv[0]);
00072 return 1;
00073 }
00074
00075 string model_dir = argv[1];
00076 string output_img = (argc >= 8 ? argv[7] : "");
00077 float z = (argc >= 3 ? atof(argv[2]) : 1.f);
00078 bool there_is_rotation = (argc >= 7);
00079 float r[3], a;
00080 a = 0;
00081
00082 if(there_is_rotation)
00083 {
00084 r[0] = atof(argv[3]);
00085 r[1] = atof(argv[4]);
00086 r[2] = atof(argv[5]);
00087 a = atof(argv[6]) / 180.f * M_PI;
00088
00089 there_is_rotation = (r[0] != 0 || r[1] != 0 || r[2] != 0) && (a != 0);
00090 }
00091
00092 ObjectModel model;
00093 try
00094 {
00095 model.loadDirectory(model_dir, true);
00096 }catch(std::string ex)
00097 {
00098 ROS_ERROR("Error: %s", ex.c_str());
00099 return 3;
00100 }
00101
00102 if(model.Faces.empty())
00103 {
00104 ROS_WARN("There are no faces in the given model");
00105 return 2;
00106 }
00107
00108 cv::Mat im(480, 640, CV_8UC3);
00109 im = cvScalar(255,255,255);
00110
00111 float f = model.Faces[0].A.at<float>(0,0);
00112 cv::Mat A = (cv::Mat_<float>(3, 3) << f, 0, 320, 0, f, 240, 0, 0, 1);
00113 cv::Mat cTo = DUtilsCV::Transformations::transl(0, 0, z);
00114
00115 if(there_is_rotation)
00116 {
00117 cv::Mat axis(1, 3, CV_32F, r);
00118 cTo *= DUtilsCV::Transformations::rotvec(axis, a);
00119 }
00120
00121 model.getVisualizationModel().draw(im, cTo, A);
00122
00123 if(!output_img.empty()) cv::imwrite(output_img, im);
00124
00125 DUtilsCV::GUI::showImage(im);
00126
00127 return 0;
00128
00129 }
00130
00131
00132