Jafar
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
imageTools.hpp
Go to the documentation of this file.
00001 
00009 #ifndef IMAGETOOLS_HPP_
00010 #define IMAGETOOLS_HPP_
00011 
00012 #include "rtslam/gaussian.hpp"
00013 #include "image/Image.hpp"
00014 
00015 namespace jafar {
00016   namespace image {
00017 
00018     template<class Vec>
00019     cv::Rect gauss2rect(const Vec & x, double dx, double dy){
00020         double xmin = (int) (x(0) - dx);
00021         double xmax = (int) (x(0) + dx);
00022         double ymin = (int) (x(1) - dy);
00023         double ymax = (int) (x(1) + dy);
00024 
00025         cv::Rect rect(xmin, ymin, xmax - xmin + 1, ymax - ymin + 1);
00026         return rect;
00027     }
00028 
00029     
00030     template<class Vec, class Sym_mat>
00031     cv::Rect gauss2rect(const Vec & x, const Sym_mat & P, double n_sigmas = 3.0){
00032         double dx = n_sigmas * sqrt(P(0,0));
00033         double dy = n_sigmas * sqrt(P(1,1));
00034         return gauss2rect(x, dx, dy);
00035     }
00036 
00037     cv::Rect gauss2rect(const rtslam::Gaussian & g, double sigma = 3.0){
00038       return gauss2rect(g.x(), g.P(), sigma);
00039     }
00040 
00047     void extractPatch(const Image & src, const vec2 & pix, Image & patch){
00048       int shift_x = (patch.width()-1)/2;
00049       int shift_y = (patch.height()-1)/2;
00050       int x_src = (int)(pix(0)-0.5) - shift_x;
00051       int y_src = (int)(pix(1)-0.5) - shift_y;
00052       src.copy(patch, x_src, y_src, 0, 0, patch.width(), patch.height());
00053     }
00054 
00063     Image extractPatch(const Image & src, const vec2 & pix, int width, int height){
00064       Image patch(width, height, src.depth(), src.colorSpace());
00065       extractPatch(src, pix, width, height);
00066       return patch;
00067     }
00068 
00069   }
00070 }
00071 
00072 #endif /* IMAGETOOLS_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on Wed Oct 15 2014 00:37:26 for Jafar by doxygen 1.7.6.1
LAAS-CNRS