title: How to use the OTSU Threshold in opencv?
body: <p>I was using a fixed threshold but turns out that it's not so good for me. Then, someone told me about the otsu threshold. How can I use it in my code?
  I read about it and I don't understand very well. Could someone explain to me how to use it in OpenCV the otsu threshold?</p>
  <p>Here is my code now:</p>
  <pre class="lang-c prettyprint-override"><code>    #include &lt;opencv2/imgproc/imgproc.hpp&gt;
      #include &lt;opencv2/highgui/highgui.hpp&gt;
  
      using namespace cv;
  
      int main ( int argc, char **argv )
      {
         Mat im_gray = imread(&quot;img3.jpg&quot;,CV_LOAD_IMAGE_GRAYSCALE);
  
         Mat im_rgb  = imread(&quot;img3.jpg&quot;);
         cvtColor(im_rgb,im_gray,CV_RGB2GRAY);
  
         Mat img_bw = im_gray &gt; 115;
  
         imwrite(&quot;img_bw3.jpg&quot;, img_bw);
  
         return 0;
      }  
  </code></pre>
  <p>With this I have to change the threshold to any image that I want to convert to binary. I found this:</p>
  <pre><code>    cvThreshold(scr, dst, 128, 255, CV_THRESH_BINARY | CV_THRESH_OTSU);
  </code></pre>
  <p>Is that right?
  I don't understand very well and because of that, didn't know how I could adapt to my code.</p>