I am trying to count the number of objects in this image:
I have a code for that:
import cv2
import numpy as np
image = cv2.imread('d:\obj.jpg')
blurred = cv2.pyrMeanShiftFiltering(image,31,91)
gray = cv2.cvtColor(blurred,cv2.COLOR_BGR2GRAY)
ret , threshold = cv2.threshold(gray,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
cv2.imshow("Threshold",threshold)
_, contours,_=cv2.findContours(threshold,cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
print "Number of contours: %d "%len(contours)
cv2.drawContours(image,contours,-1,(0,255,255),2)
cv2.namedWindow('Display',cv2.WINDOW_NORMAL)
cv2.imshow('Display',image)
cv2.waitKey()
the number of objects is 9, but the output is 1015.
when I try to show the the objects this is what I get:
How can I fix that? thanks to all :)

