Count the number of objects OpenCV - Python
<p>This is my first project in Python(3.5.1) and OpenCV (3), so I'm sorry for my mistakes.
I've some pictures like these ones:
<a href="https://s12.postimg.org/ox8gw5l8d/gado.jpg" rel="nofollow">https://s12.postimg.org/ox8gw5l8d/gado.jpg</a></p>

<p>I need to count how many white objects has on this image. I tried to ise SimpleBlobDetector but I didn't work as I was expecting.</p>

<pre><code># Standard imports
import cv2
import numpy as np;

# Read image
im = cv2.imread("C:/opencvTests/cattle.jpg", cv2.IMREAD_GRAYSCALE)

# Setup SimpleBlobDetector parameters.
params = cv2.SimpleBlobDetector_Params()

#filter by color
params.filterByColor = True
params.blobColor = 255

# Filter by Convexity
params.filterByConvexity = True
params.minConvexity = 0.87

# Filter by Inertia
params.filterByInertia = True
params.minInertiaRatio = 0.08

# Create a detector with the parameters
ver = (cv2.__version__).split('.')
if int(ver[0]) &lt; 3 :
   detector = cv2.SimpleBlobDetector(params)
else : 
detector = cv2.SimpleBlobDetector_create(params)

# Detect blobs.
keypoints = detector.detect(im)

# Draw detected blobs as red circles.
# cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS ensures the size of the circle        corresponds to the size of blob
im_with_keypoints = cv2.drawKeypoints(im, keypoints, np.array([]),   (0,0,255),     cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

# Show keypoints
cv2.imwrite("C:/opencvTests/blobSave.jpg",im_with_keypoints)
print("Total of objects")
print(len(keypoints))
</code></pre>

<p>Any help would be really appreciate! Thanks in advance </p>

<p>Probably you will end up in wrong count if you continue working on this image. Perform some pre-processing operations such as morphological operations to remove noise and also to separate the object from each other. After this make use of "findcontours" an inbuilt opencv function. Then read the size of "findcontours" this will give the count of the objects.</p>

python opencv