title: OpenCV cpp motion detection
body: <p>I'm trying to figure out how motion detection work in opencv.</p>
  
  <p>I can see there the video analysis reference but I don't find enough information about how this is used.</p>
  
  <p>I've also seen some people using absdiff I tried it like this, but It gives me an exception at memore errors</p>
  
  <blockquote>
    <p>OpenCV Error: Sizes of input arguments do not match (The operation is neither 'a
    rray op array' (where arrays have the same size and the same number of channels)
    , nor 'array op scalar', nor 'scalar op array') in cv::arithm_op, file C:\builds
    \2_4_PackSlave-win32-vc12-shared\opencv\modules\core\src\arithm.cpp, line 1287</p>
  </blockquote>
  
  <p>the code is </p>
  
  <pre><code>#include &lt;iostream&gt;
  #include &lt;sstream&gt;
  #include &lt;string&gt;
  #include &lt;opencv2/core/core.hpp&gt;
  #include &lt;opencv2/imgproc/imgproc.hpp&gt;
  #include &lt;opencv2/highgui/highgui.hpp&gt;
  
  using namespace cv;
  using namespace std;
  
  int main()
  {
      //create matrix for storage
      Mat image;
      Mat image2;
      Mat image3;
      Mat image4;
  
      //initialize capture
      VideoCapture cap;
      cap.open(0);
  
      //create window to show image
      namedWindow("window", 1);
  
      while (1){
  
          //copy webcam stream to image
          cap &gt;&gt; image;
          cap &gt;&gt; image2;
  
          absdiff(image, image2, image3);
          threshold(image3, image4, 128, 255, THRESH_BINARY);
  
  
          //print image to screen
          if (!image.empty()) {
  
              imshow("window", image3);
  
          }
  
          //delay33ms
  
          waitKey(10);
  
          //
      }
  
  }
  </code></pre>
  
  <p>im obviously not using it right</p>