title: How to extract coins out of an image?
body: <p>So I want to segment and extract the coins out of the image and use them for other purposes. But I ran into problems extracting those coins out first. The background shouldn't be white all the time.</p>
  <p><a href="https://i.stack.imgur.com/QJk75.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QJk75m.jpg" alt="enter image description here" /></a></p>
  <p>I've tried thresholding and find the contours, but it returns more contours than expected. What should I do?</p>
  <pre><code>cv::Mat coinpic, backgroundpic, diffpic, newpic, threshold;
  
  cv::cvtColor([self cvMatFromUIImage:coins], coinpic, cv::COLOR_BGR2GRAY);
  
  cv::threshold(coinpic, diffpic, 200, 255, cv::THRESH_BINARY_INV+cv::THRESH_OTSU);
  
  vector&lt;vector&lt;cv::Point&gt;&gt; contours;
  vector&lt;cv::Vec4i&gt; hierarchy;
  
  cv::findContours(diffpic, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE);
  
  cout &lt;&lt; contours.size() &lt;&lt; endl;
  
  return [self UIImageFromCVMat:diffpic];
  </code></pre>
  <p>The result I expect is like this following link: <a href="https://docs.opencv.org/3.4.3/d3/db4/tutorial_py_watershed.html" rel="nofollow noreferrer">https://docs.opencv.org/3.4.3/d3/db4/tutorial_py_watershed.html</a></p>