title: While finding a difference between 2 pictures OpenCV difference is bigger than it is supposed to be
body: <p>I'm working with OpenCV (in Android NDK) and I have a problem. I want to find differences between two pictures, and than cut the difference. However, following output made difference bigger. I used images from this question <a href="https://stackoverflow.com/questions/27035672/cv-extract-differences-between-two-images">CV - Extract differences between two images</a> . And I tried to solve it but unsuccessfully. Here is the output</p>
  
  <pre><code>Mat&amp; backgroundImage = *(Mat*) addrRgba;
  Mat&amp; currentImage = *(Mat*) addrRgba2;
  Mat diffImage;
  absdiff(backgroundImage, currentImage, diffImage);
  Mat mask=currentImage.clone();
  
            float threshold = 30.0f;
              float dist;
  
            for(int j=0; j&lt;diffImage.rows; ++j)
                for(int i=0; i&lt;diffImage.cols; ++i)
                {
                    if(diffImage.at&lt;cv::Vec3b&gt;(j,i)==Vec3b(0,0,0)){
                      Point center( i , j);
                     circle (mask,center,1,Scalar( 255, 255, 255 ),-1,9,0);
                    }
  
                }
  
                 currentImage=mask;
  </code></pre>
  
  <p>FIRST IMAGE
  <a href="https://i.stack.imgur.com/MoydX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MoydX.png" alt="enter image description here"></a>
  SECOND IMAGE
  <a href="https://i.stack.imgur.com/eqYN5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/eqYN5.png" alt="enter image description here"></a>
  RESULT
  <a href="https://i.stack.imgur.com/ptJPi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ptJPi.png" alt="enter image description here"></a></p>
  
  <p>On the other hand , this code gives me output like this </p>
  
  <pre><code>Mat&amp; backgroundImage = *(Mat*) addrRgba;
  Mat&amp; currentImage = *(Mat*) addrRgba2;
  Mat diffImage;
  
        absdiff(backgroundImage, currentImage, diffImage);
        Mat gray;
  
        cvtColor(diffImage,gray, COLOR_BGR2GRAY);
  
        equalizeHist( gray, gray );
        Mat mask=currentImage.clone();
        cvtColor(mask,mask, COLOR_BGR2GRAY);
        float threshold = 30.0f;
        float dist;
  
                  for(int j=0; j&lt;gray.rows; ++j)
                      for(int i=0; i&lt;gray.cols; ++i)
                      {
                          cv::Vec3b pix = gray.at&lt;cv::Vec3b&gt;(j,i);
  
                          if(pix==Vec3b(0,0,0)){
  
                                Point center( i , j);
                                circle (mask,center,1,Scalar( 255, 255, 255 ),-1,9,0);
                          }
                      }
                      Mat maskedImage;
                  diffImage.copyTo(maskedImage,mask);
                 currentImage=mask;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/wVYec.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wVYec.png" alt="enter image description here"></a>
  ps:sorry for no design</p>