title: Opencv C++ Thresholding not working after absdiff, Barcode Detection
body: <p>I am trying to detect barcode from an image using OpenCv, 
  I am using the gradient method: <a href="http://www.pyimagesearch.com/2014/11/24/detecting-barcodes-images-python-opencv/" rel="nofollow noreferrer">http://www.pyimagesearch.com/2014/11/24/detecting-barcodes-images-python-opencv/</a>
  With help from the following question: <a href="https://stackoverflow.com/questions/9013703/how-to-find-the-location-of-red-region-in-an-image-using-matlab/9014569">How to find the location of red region in an image using MATLAB?</a></p>
  
  <p>Code:</p>
  
  <pre><code>Mat imgco,img,imgx,imgy,thresh;
  imgco = imread("/Users/a/Desktop/barcode_01.jpg");
  
  //### Convert image to grayscale ###
  cvtColor(imgco,img,CV_BGR2GRAY);
  imshow("img", img);
  waitKey(0);
  
  //### Finding horizontal and vertical gradient ###
  
  Sobel(img,imgx,CV_16S,1,0,-1,50,0,BORDER_DEFAULT);
  imgx = abs(imgx);
  imshow("img", imgx);
  waitKey(0);
  
  Sobel(img,imgy,CV_16S,0,1,-1,50,0,BORDER_DEFAULT);
  imgy = abs(imgy);
  imshow("img", imgy);
  waitKey(0);
  
  absdiff(imgx, imgy, img);
  imshow("img", img);
  waitKey(0);
  
  //### Low pass filtering ###
  GaussianBlur(img, img, Size(9,9), 0);
  imshow("img", img);
  waitKey(0);
  
  //### Applying Threshold ###
  threshold(img,thresh,225,255,CV_THRESH_BINARY);
  imshow("img", thresh);
  waitKey(0);
  </code></pre>
  
  <p>Now the program works correctly upto gaussian blur, Somehow trying to threshold the image gives a blank output. Can anyone suggest what could be the issue? </p>
  
  <p><img src="https://i.stack.imgur.com/LKIu8.png" alt="Gaussian Output:">
  <img src="https://i.stack.imgur.com/sVAH6.png" alt="Threshold Output:"></p>
  
  <p>Thank You.</p>
  
  <p>UPDATE: Applying the threshold operation before AbsDiff, Results in thresholding correctly. Hence there is something related to using AbsDiff, that is messing up with thresholding. Any help?</p>
  
  <p>UPDATE 2: Comparing my output with the following: <a href="http://www.pyimagesearch.com/wp-content/uploads/2014/11/barcode_gradient_and_detection.jpg" rel="nofollow noreferrer">http://www.pyimagesearch.com/wp-content/uploads/2014/11/barcode_gradient_and_detection.jpg</a> I realize that I am getting a grey image while the author is getting a crisp black bacground? Even when we are performing the same operations. Thank you.</p>