title: Identify and count objects different from background
body: <p>I try to use python, NumPy, and OpenCV to analyze the image below and just draw a circle on each object found. The idea here is not to identify the bug only identify any object that is different from the background.</p>
  <p>Original Image:
  <a href="https://i.stack.imgur.com/ykK7A.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ykK7A.jpg" alt="enter image description here" /></a></p>
  <p>Here is the code that I'm using.</p>
  <pre><code>import cv2
  import numpy as np
  img = cv2.imread('per.jpeg', cv2.IMREAD_GRAYSCALE)
  if cv2.__version__.startswith('2.'):
      detector = cv2.SimpleBlobDetector()
  else:
      detector = cv2.SimpleBlobDetector_create()
  keypoints = detector.detect(img)
  print(len(keypoints))
  imgKeyPoints = cv2.drawKeypoints(img, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
  status = cv2.imwrite('teste.jpeg',imgKeyPoints)
  print(&quot;Image written to file-system : &quot;,status)
  </code></pre>
  <p>But the problem is that I'm getting only a greyscale image as result without any counting or red circle, as shown below:
  <a href="https://i.stack.imgur.com/Dhx5d.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Dhx5d.jpg" alt="enter image description here" /></a></p>
  <p>Since I'm new to OpenCV and object recognition world I'm not able to identify what is wrong, and any help will be very appreciated.</p>