Mask.cpp
Go to the documentation of this file.
00001 
00033 #include <opencv/cv.h>
00034 #include <opencv/highgui.h>
00035 #include "Mask.h"
00036 
00037 // ---------------------------------------------------------------------------
00038 
00039 Mask::Mask(const char *filename)
00040 {
00041   m_original_mask = cv::imread(filename, 0);
00042   m_current_mask = m_original_mask.clone();
00043 }
00044 
00045 // ---------------------------------------------------------------------------
00046   
00047 Mask::Mask(const cv::Mat &mask)
00048 {
00049   m_original_mask = mask.clone();
00050   m_current_mask = m_original_mask.clone();
00051 }
00052 
00053 // ---------------------------------------------------------------------------
00054   
00055 Mask::~Mask()
00056 {
00057 }
00058 
00059 // ---------------------------------------------------------------------------
00060 
00061 void Mask::shrink(int margin)
00062 {
00063   if(margin > 0)
00064   {
00065     cv::Mat erosion = cv::Mat::ones(margin*2+1, margin*2+1, CV_8U);
00066     cv::Mat aux;
00067     cv::erode(m_current_mask, aux, erosion);
00068     m_current_mask = aux;
00069   }
00070 }
00071 
00072 // ---------------------------------------------------------------------------
00073   
00074 void Mask::reset()
00075 {
00076   m_current_mask = m_original_mask.clone();
00077 }
00078 
00079 // ---------------------------------------------------------------------------
00080 
00081 void Mask::maskKeyPoints(std::vector<cv::KeyPoint> &keys)
00082 {
00083   int deleted = 0;
00084   const int N = keys.size();
00085   cv::KeyPoint aux;
00086   
00087   int i = 0;
00088   while(i < N - deleted)
00089   {
00090     if(!m_current_mask.at<unsigned char>(keys[i].pt.y, keys[i].pt.x))
00091     {
00092       // move to the last position
00093       aux = keys[ N - 1 - deleted ];
00094       keys[ N - 1 - deleted ] = keys[i];
00095       keys[i] = aux;
00096       ++deleted;
00097     }
00098     else
00099     {
00100       ++i;
00101     }
00102   }
00103 
00104   if(deleted) keys.resize(N - deleted);
00105 }
00106 
00107 // ---------------------------------------------------------------------------
00108 
00109 void Mask::getPointsOutsideMask(const std::vector<cv::KeyPoint> &keys, 
00110     std::vector<unsigned int> &i_out) const
00111 {
00112   i_out.clear();
00113   
00114   for(unsigned int i = 0; i < keys.size(); ++i)
00115   {
00116     if(!test(keys[i].pt.x, keys[i].pt.y)) i_out.push_back(i);
00117   }
00118   
00119 }
00120 
00121 // ---------------------------------------------------------------------------
00122 
00123 


re_vision
Author(s): Dorian Galvez-Lopez
autogenerated on Sun Jan 5 2014 11:31:52