title: setting blob detection parameters in python
body: <p>I am running blob detection on a camera image of circular objects, using OpenCV 2.4.9. I run a number of standard filters on the image (blur, adaptive threshold, skeletonization using skimage routines, and dilation of the skeleton), and would like to identify blobs (contiguous black areas) on the result. There is SimpleBlobDetector just for that, but however I set its parameters, it is not doing what I would like to.</p>
  
  <p>This is the original image:
  <a href="https://i.stack.imgur.com/7fYA2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7fYA2.png" alt="caputred image"></a></p>
  
  <p>and this is the processed version, with keypoints from the detector drawn in yellow:
  <a href="https://i.stack.imgur.com/chjPF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/chjPF.png" alt="skeletonization"></a></p>
  
  <p>The keypoints don't seem to respect area constraints, and also don't appear where I would expect them.</p>
  
  <p>The script looks like the following, is there something obviously wrong? Or any other suggestions?</p>
  
  <pre><code>import numpy as np
  import cv2
  import skimage, skimage.morphology
  
  img0=cv2.imread('capture_b_07.cropped.png')
  img1=cv2.cvtColor(img0,cv2.COLOR_BGR2GRAY)
  img2=cv2.medianBlur(img1,5)
  img3=cv2.bilateralFilter(img2,9,75,75)
  img4=cv2.adaptiveThreshold(img3,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,cv2.THRESH_BINARY_INV,21,0)
  img5=skimage.img_as_ubyte(skimage.morphology.skeletonize(skimage.img_as_bool(img4)))
  img6=cv2.dilate(img5,cv2.getStructuringElement(cv2.MORPH_RECT,(3,3)),iterations=1)
  # blob detection
  pp=cv2.SimpleBlobDetector_Params()
  pp.filterByColor=True
  pp.blobColor=0
  pp.filterByArea=True
  pp.minArea=500
  pp.maxArea=5000
  pp.filterByCircularity=True
  pp.minCircularity=.4
  pp.maxCircularity=1.
  
  det=cv2.SimpleBlobDetector(pp)
  keypts=det.detect(img6)
  img7=cv2.drawKeypoints(img6,keypts,np.array([]),(0,255,255),cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
  cv2.imwrite('capture_b_07.blobs.png',img7)
  </code></pre>
  
  <p>Similar pipeline from ImageJ (Analyze Particles, circularity 0.5-1.0, area 500-5000 px^2), which I am trying to reproduce using OpenCV, gives something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/75qRs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/75qRs.png" alt="imagej blobs"></a></p>