title: Detecting binary blobs in OpenCV
body: <p>I have some colored rectangles in my image that I successfully recognize by HSV thresholding. The result looks like this:
  <a href="https://i.stack.imgur.com/xHIa2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xHIa2.png" alt="mask image"></a></p>
  
  <p>Now I want to detect the big blob as one point. I tried it with <code>cv2.SimpleBlobDetector()</code> and custom parameters:</p>
  
  <pre><code>import cv2
  import numpy as np
  
  mask = cv2.imread('mask.png')
  original = cv2.imread('original.png')
  params = cv2.SimpleBlobDetector_Params()
  # thresholds
  params.minThreshold = 10
  params.maxThreshold = 200
  #params.thresholdStep = 20
  
  # filter by area
  params.filterByArea = True
  params.minArea = 1
  params.maxArea = 10000
  
  # filter by circularity
  params.filterByCircularity = False
  
  # filter by convexity
  params.filterByConvexity = False
  
  # filter by inertia
  params.filterByInertia = False
  
  detector = cv2.SimpleBlobDetector(params)
  
  keypoints = detector.detect(mask)
  img_keypoints = cv2.drawKeypoints(original, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
  cv2.imwrite('keypoints.png', img_keypoints)
  </code></pre>
  
  <p>This is how the result AND the original picture looks like:
  <a href="https://i.stack.imgur.com/OK8Vd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OK8Vd.png" alt="keypoints and original"></a></p>
  
  <p>I would expect a red point sitting in the center of the green point.</p>
  
  <p>How can I fix this? Help is very appreciated.</p>
  
  <p><strong>EDIT:</strong> I forgot to mention: Is it really necessary to generate multiple binary images in <code>cv2.SimpleBlobDetector()</code> since I already have a binary image as input? Is it OK to change the  values to the following:</p>
  
  <pre><code>params.minThreshold = 127
  params.maxThreshold = 127
  </code></pre>
  
  <p>to reduce unnecessary CPU usage by generating binary images?</p>
  
  <p><strong>EDIT2</strong> : Please note that I'm using OpenCV 2, not 3</p>
  
  <p>Thank you.</p>