title: accumulatedweight throws cv:Exception error
body: <p>I am new to OpenCV and trying to find contours and draw rectangle on them, here's my code but its throwing cv::Exception when it comes to accumulatedweighted().
  i tried to make both src(Original Image) and dst(background) by converting to CV_32FC3 and then finding avg using accumulatedweighted.</p>
  
  <pre><code>#include "opencv2/video/tracking.hpp"
  #include "opencv2/imgproc/imgproc.hpp"
  #include "opencv2/imgproc/imgproc_c.h"
  #include "opencv2/highgui/highgui.hpp"
  
  #include &lt;iostream&gt;
  #include &lt;ctype.h&gt;
  
  using namespace cv;
  using namespace std;
  
  static void help()
  {
  cout &lt;&lt; "\nThis is a Example to implement CAMSHIFT to detect multiple motion objects.\n";
  }
  
  Rect rect;
  VideoCapture capture;
  Mat currentFrame, currentFrame_grey, differenceImg, oldFrame_grey,background;
  vector&lt;vector&lt;Point&gt; &gt; contours;
  vector&lt;Vec4i&gt; hierarchy;
  
  bool first = true;
  
  int main(int argc, char* argv[])
  {
  //Create a new movie capture object.
  capture.open(0);
  
  if(!capture.isOpened())
  {
      //error in opening the video input
      cerr &lt;&lt; "Unable to open video file: " /*&lt;&lt; videoFilename*/ &lt;&lt; endl;
      exit(EXIT_FAILURE);
  }   
  
  //capture current frame from webcam
  capture &gt;&gt; currentFrame;
  
  //Size of the image.
  CvSize imgSize;
  imgSize.width = currentFrame.size().width; //img.size().width
  imgSize.height = currentFrame.size().height; ////img.size().height
  
  //Images to use in the program.
  currentFrame_grey.create( imgSize, IPL_DEPTH_8U);//image.create().  
  
  while(1)
  {
      capture &gt;&gt; currentFrame;//VideoCapture&amp; VideoCapture::operator&gt;&gt;(Mat&amp; image)                
  
      //Convert the image to grayscale.
      cvtColor(currentFrame,currentFrame_grey,CV_RGB2GRAY);//cvtColor()
  
      currentFrame.convertTo(currentFrame,CV_32FC3);
      background = Mat::zeros(currentFrame.size(), CV_32FC3);
      accumulateWeighted(currentFrame,background,1.0,NULL);
  
      imshow("Background",background);
  
      if(first) //Capturing Background for the first time
      {
          differenceImg = currentFrame_grey.clone();//img1 = img.clone()
          oldFrame_grey = currentFrame_grey.clone();//img2 = img.clone()
          convertScaleAbs(currentFrame_grey, oldFrame_grey, 1.0, 0.0);//convertscaleabs()
          first = false;
          continue;
      }
  
      //Minus the current frame from the moving average.
      absdiff(oldFrame_grey,currentFrame_grey,differenceImg);//absDiff()
  
      //bluring the differnece image
      blur(differenceImg, differenceImg, imgSize);//blur()
  
      //apply threshold to discard small unwanted movements
      threshold(differenceImg, differenceImg, 25, 255, CV_THRESH_BINARY);//threshold()
  
      //find contours
      findContours(differenceImg,contours,hierarchy,CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0)); //findcontours()
  
      //draw bounding box around each contour
      //for(; contours! = 0; contours = contours-&gt;h_next)
      for(int i = 0; i &lt; contours.size(); i++)
      {
          rect = boundingRect(contours[i]); //extract bounding box for current contour
          //drawing rectangle
          rectangle(currentFrame, cvPoint(rect.x, rect.y), cvPoint(rect.x+rect.width, rect.y+rect.height), cvScalar(0, 0, 255, 0), 2, 8, 0);                 
      }       
  
      //New Background
      convertScaleAbs(currentFrame_grey, oldFrame_grey, 1.0, 0.0);
  
      //display colour image with bounding box
      imshow("Output Image", currentFrame);//imshow()
  
      //display threshold image
      imshow("Difference image", differenceImg);//imshow()
  
      //clear memory and contours
      //cvClearMemStorage( storage );
      //contours = 0;
      contours.clear();
  
      //background = currentFrame;
  
      //press Esc to exit
      char c = cvWaitKey(33);
      if( c == 27 ) break;
  
  }
  
  // Destroy All Windows.
  destroyAllWindows();
  
  return 0;
  }
  </code></pre>
  
  <p>Please Help to solve this.</p>