1 /* 2 * Model.cpp 3 * 4 * Created on: Apr 9, 2014 5 * Author: edgar 6 */ 7 8 #include "Model.h" 9 #include "CsvWriter.h" 10 11 Model::Model() : list_points2d_in_(0), list_points2d_out_(0), list_points3d_in_(0) 12 { 13 n_correspondences_ = 0; 14 } 15 16 Model::~Model() 17 { 18 // TODO Auto-generated destructor stub 19 } 20 21 void Model::add_correspondence(const cv::Point2f &point2d, const cv::Point3f &point3d) 22 { 23 list_points2d_in_.push_back(point2d); 24 list_points3d_in_.push_back(point3d); 25 n_correspondences_++; 26 } 27 28 void Model::add_outlier(const cv::Point2f &point2d) 29 { 30 list_points2d_out_.push_back(point2d); 31 } 32 33 void Model::add_descriptor(const cv::Mat &descriptor) 34 { 35 descriptors_.push_back(descriptor); 36 } 37 38 void Model::add_keypoint(const cv::KeyPoint &kp) 39 { 40 list_keypoints_.push_back(kp); 41 } 42 43 44 /** Save a CSV file and fill the object mesh */ 45 void Model::save(const std::string path) 46 { 47 cv::Mat points3dmatrix = cv::Mat(list_points3d_in_); 48 cv::Mat points2dmatrix = cv::Mat(list_points2d_in_); 49 //cv::Mat keyPointmatrix = cv::Mat(list_keypoints_); 50 51 cv::FileStorage storage(path, cv::FileStorage::WRITE); 52 storage << "points_3d" << points3dmatrix; 53 storage << "points_2d" << points2dmatrix; 54 storage << "keypoints" << list_keypoints_; 55 storage << "descriptors" << descriptors_; 56 57 storage.release(); 58 } 59 60 /** Load a YAML file using OpenCv functions **/ 61 void Model::load(const std::string path) 62 { 63 cv::Mat points3d_mat; 64 65 cv::FileStorage storage(path, cv::FileStorage::READ); 66 storage["points_3d"] >> points3d_mat; 67 storage["descriptors"] >> descriptors_; 68 69 points3d_mat.copyTo(list_points3d_in_); 70 71 storage.release(); 72 73 } 74