o.st.
o.st.

Reputation: 5

SimpleBlobDetector opencv python error but missing output

I am trying to work with the opencv SimpleBlobDetector. My current program is a simple test program like this:

import cv2
import numpy as np;

im = cv2.imread("blobs.jpg", cv2.IMREAD_GRAYSCALE)

params = cv2.SimpleBlobDetector_Params()

params.filterByArea = True;
params.minArea = 1;
params.maxArea = 1000;

detector = cv2.SimpleBlobDetector(params)

keypoints = detector.detect(im)

im_with_keypoints = cv2.drawKeypoints(im, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

cv2.imshow("Keypoints", im_with_keypoints)
cv2.waitKey(0)

code runs until the keypoints line where it should actually detect the blobs. it doesnt show any error message but just restarts the kernel. i used a very easy picture so blobs should be detected.

used image

Upvotes: 0

Views: 365

Answers (1)

Paddy Harrison
Paddy Harrison

Reputation: 2012

Seems to work for me. If you are using Python 3 you want to use detector = cv2.SimpleBlobDetector_create(params) rather than what you had before. I increased the max area to 10000 pixels and I've included a screenshot of the output too:

import cv2
import numpy as np;

im = cv2.imread("blobs.jpg", cv2.IMREAD_GRAYSCALE)

params = cv2.SimpleBlobDetector_Params()

params.filterByArea = True;
params.minArea = 1;
params.maxArea = 10000;

detector = cv2.SimpleBlobDetector_create(params)

keypoints = detector.detect(im)

im_with_keypoints = cv2.drawKeypoints(im, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

cv2.imshow("Keypoints", im_with_keypoints)
cv2.waitKey(0)

output

Upvotes: 1

Related Questions