I want to tag on the original image with the blobs that are found. But whenever I do the blob detection it only will make a new image like this:
Outcome image after blob:
However, I want to show the original image with the red tagging on it. Original image:
I just use the regular code for the blob detection. Is there another way to do the red circles on the original image? So its clear where they are.
im_gray = cv2.imread(img,cv2.IMREAD_GRAYSCALE)
(thresh, im_bw) = cv2.threshold(im_gray, 128, 255,cv2.THRESH_BINARY |
cv2.THRESH_OTSU)
thresh = 50
im_bw = cv2.threshold(im_gray, thresh, 255, cv2.THRESH_BINARY)[1]
#detect blobs based on features
params = cv2.SimpleBlobDetector_Params()
# Filter by Area.
params.filterByArea = True
params.minArea = 70
params.maxArea = 150
# Filter by Color (black=0)
params.filterByColor = False # Set true for cast_iron as we'll be detecting black regions
params.blobColor = 0
# Filter by Circularity
params.filterByCircularity = True
params.minCircularity = 0.5
params.maxCircularity = 1
# Filter by Convexity
params.filterByConvexity = True
params.minConvexity = 0.5
params.maxConvexity = 1
# Filter by InertiaRatio
params.filterByInertia = True
params.minInertiaRatio = 0.3
params.maxInertiaRatio = 0.9
# Distance Between Blobs
params.minDistBetweenBlobs = 0
#thresholded to value 70 detecting blobs:
detector = cv2.SimpleBlobDetector_create(params)
keypoints = detector.detect(im_bw)
print("Number of blobs detected are : ", len(keypoints))
#detect blobs: missing the detection based on features
im_with_keypoints = cv2.drawKeypoints(im_bw, keypoints, numpy.array([]), (0, 0, 255),
cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
Your problem is your last line:
im_with_keypoints = cv2.drawKeypoints(im_bw, keypoints, numpy.array([]), (0, 0, 255),
cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
Here you draw your key points on im_bw
, which is not your original image but your thresholded image. If you replace im_bw
here with your original image (e.g. use your grayscale version you already loaded as im_gray
) you should get your desired result.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With