I have a problem finding the contours of black objects on white background.
here I added an example of an image. Now I need to find center of black regions and I use following code.
im = cv2.imread(img)
plt.imshow(im)
gray = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
thresh = cv2.threshold(im, 60, 255, cv2.THRESH_BINARY_INV)
cnts = cv2.findContours(thresh, cv2.RETR_EXTERNAL,cv2.CHAIN_APPROX_SIMPLE)
cnts = imutils.grab_contours(cnts)
However it gives an error like
TypeError: Expected Ptr for argument 'image' " for the image argument of cv2.findeContours().
How can I solve this? or if you have any other idea how to find center of black regions I would like to hear. Thanks.



