title: Error No matching function for call - even when changed to const xxxx&
body: <p>I am new to openCV. I found this particular code that I would like to execute:</p>
  
  <p><a href="https://gist.github.com/t-abe/1055619" rel="nofollow">https://gist.github.com/t-abe/1055619</a></p>
  
  <p>I changed line 114 to <strong>void mainLoop(const Func&amp; func)</strong> as suggested, however still receive the following error:</p>
  
  <blockquote>
    <p><code>error: no matching function for call to ‘InteractiveGrabcut::mainLoop(main()::&lt;lambda(InteractiveGrabcut*, int)&gt;)’ note: candidate is: note: template&lt;class Func&gt; void InteractiveGrabcut::mainLoop(const Func&amp;)</code></p>
  </blockquote>
  
  <p>I'm at a loss here. Any help would be much appreciated...
  Thanks!</p>
  
  <p>Here's the code:</p>
  
  <pre><code>#include &lt;useopencv.h&gt;
  #include &lt;string&gt;
  #include &lt;vector&gt;
  #include &lt;iostream&gt;
  
  class InteractiveGrabcut {
      cv::Mat src;
      cv::Mat fgd, bgd;
      bool ldrag, rdrag;
      std::string name;
  public:
      cv::Mat mask;
      //cv::Rect rect;
      cv::Point lstart, rstart;
      cv::Scalar fg_color, bg_color;
  
      InteractiveGrabcut()
          : src(), mask(), fgd(), bgd(),
           ldrag(false), rdrag(false), name("igc"),
           fg_color(0, 0, 255), bg_color(255, 0, 0)
      {};
  
      InteractiveGrabcut(const cv::Mat&amp; src_)
           : src(src_), mask(), fgd(), bgd(),
            ldrag(false), rdrag(false), name("igc"), fg_color(0, 0, 255), bg_color(255, 0, 0)
          {
              mask = cv::Mat::ones(src_.size(), CV_8U) * cv::GC_PR_BGD;
       };
  
      void prepareWindow(const std::string name){
      this-&gt;name = name;
      cv::namedWindow(name);
      cv::setMouseCallback(name, events, this);
  };
  
  static void events( int e, int x, int y, int flags, void* s ){
      InteractiveGrabcut* self = (InteractiveGrabcut*)s;
      cv::Point pt(x, y);
      switch(e) {
      case CV_EVENT_LBUTTONDOWN:
          self-&gt;ldrag = true;
          self-&gt;lstart = pt;
          break;
      case CV_EVENT_LBUTTONUP:
          self-&gt;ldrag = false;
          break;
      case CV_EVENT_RBUTTONDOWN:
          self-&gt;rdrag = true;
          self-&gt;rstart = pt;
          break;
      case CV_EVENT_RBUTTONUP:
          self-&gt;rdrag = false;
          break;
      case CV_EVENT_MOUSEMOVE:
          if(self-&gt;ldrag) {
              cv::line(self-&gt;mask, self-&gt;lstart, pt, cv::Scalar(cv::GC_FGD), 1);
              self-&gt;lstart = pt;
          }
          else if(self-&gt;rdrag) {
              cv::line(self-&gt;mask, self-&gt;rstart, pt, cv::Scalar(cv::GC_BGD), 1);
              self-&gt;rstart = pt;
          }
          break;
      default:
          break;
      };
  };
  
  void show(){
      cv::Mat scribbled_src = src.clone();
      const float alpha = 0.7f;
      for(int y=0; y &lt; mask.rows; y++){
          for(int x=0; x &lt; mask.cols; x++){
              if(mask.at&lt;uchar&gt;(y, x) == cv::GC_FGD) {
                  cv::circle(scribbled_src, cv::Point(x, y), 2, fg_color, -1);
              } else if(mask.at&lt;uchar&gt;(y, x) == cv::GC_BGD) {
                  cv::circle(scribbled_src, cv::Point(x, y), 2, bg_color, -1);
              } else if(mask.at&lt;uchar&gt;(y, x) == cv::GC_PR_BGD) {
                  cv::Vec3b&amp; pix = scribbled_src.at&lt;cv::Vec3b&gt;(y, x);
                  pix[0] = (uchar)(pix[0] * alpha + bg_color[0] * (1-alpha));
                  pix[1] = (uchar)(pix[1] * alpha + bg_color[1] * (1-alpha));
                  pix[2] = (uchar)(pix[2] * alpha + bg_color[2] * (1-alpha));
              } else if(mask.at&lt;uchar&gt;(y, x) == cv::GC_PR_FGD) {
                  cv::Vec3b&amp; pix = scribbled_src.at&lt;cv::Vec3b&gt;(y, x);
                  pix[0] = (uchar)(pix[0] * alpha + fg_color[0] * (1-alpha));
                  pix[1] = (uchar)(pix[1] * alpha + fg_color[1] * (1-alpha));
                  pix[2] = (uchar)(pix[2] * alpha + fg_color[2] * (1-alpha));
              }
          }
      }
      cv::imshow(name, scribbled_src);
      cv::imshow(name + "_FG", getFG());
  }
  
  void execute(){
      std::cout &lt;&lt; "computing...";
      cv::grabCut(src, mask, cv::Rect(), bgd, fgd, 1, cv::GC_INIT_WITH_MASK);
      std::cout &lt;&lt; "end." &lt;&lt; std::endl;
  };
  
  cv::Mat getBinMask(){
      cv::Mat binmask(mask.size(), CV_8U);
      binmask = mask &amp; 1;
      return binmask;
  };
  
  cv::Mat getFG(){
      cv::Mat fg = cv::Mat::zeros(src.size(), src.type());
      src.copyTo(fg, getBinMask());
      return fg;
  };
  
      template &lt;class Func&gt;
      void mainLoop(Func&amp; func){  //&lt;------------------------
               //tried mainLoop(const Func&amp; func)
               //      mainLoop(Func func) //no luck!
          while(1){
              int key = cv::waitKey(1);
             if(key == '\x1b')
                 break;
             func(this, key);
            show();
          }
      };
  };
  
      int main(){
      const std::string input_filename("bird.bmp");
      cv::Mat input_image = cv::imread(input_filename);
  
      InteractiveGrabcut igc(input_image);
      igc.prepareWindow("bird");
      igc.mainLoop([](InteractiveGrabcut* self, int key)-&gt;void {
         if(key == ' '){
            self-&gt;execute();
        }
      });
   }
  </code></pre>