Ask Your Question
0

SimpleBlobDetector_Params() doesn't detect the blobs on the edges of the image

asked 2019-05-30 23:28:17 -0600

levinpqr gravatar image

So I have this image of blobs below:

image description

When I ran the code below, some of the blobs on the edges of the image weren't on detected as seen on the next image.

image description

Can anyone help me with detecting the others? Thanks

params = cv2.SimpleBlobDetector_Params()
params.minDistBetweenBlobs = 10
params.filterByColor = True
params.maxArea = 10000
params.minThreshold = 10
params.maxThreshold = 200
params.filterByArea = True
params.minArea = 50
params.filterByCircularity = True
params.minCircularity = 0
params.filterByConvexity = True
params.minConvexity = 0
params.filterByInertia = True
params.minInertiaRatio = 0.1
detector = cv2.SimpleBlobDetector(params)
keypoints = detector.detect(res)
im_with_keypoints = cv2.drawKeypoints(img, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
res = cv2.drawKeypoints(res, keypoints, np.array([]), (0,0,255), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
print("LENGTH: %d" %len(keypoints))
print(keypoints)
i=0
for kp in keypoints:
    print("(%f,%f)"%(kp.pt[0],kp.pt[1]))
    i+=1
    cv2.rectangle(res,(int(kp.pt[0]),int(kp.pt[1])),(int(kp.pt[0])+1,int(kp.pt[1])+1),(0,255,0),3)
print("LEN: %d" %i)
cv2.imshow("Keypoints", im_with_keypoints)
cv2.imshow("RES", res)
cv2.waitKey(0)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2019-06-02 09:17:01 -0600

supra56 gravatar image

updated 2019-06-02 09:19:31 -0600

I solved problem:

#!/usr/bin/python3
#Raspberry pi 3B/+, OpenCV 4.1.0
#Date: 2nd June, 2019

import numpy as np
import cv2

img = cv2.imread('blob.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
blurred = cv2.medianBlur(gray, 9)
_filter = cv2.bilateralFilter(blurred, 5, 75, 75)
adap_thresh = cv2.adaptiveThreshold(_filter,
                                    255,
                                    cv2.ADAPTIVE_THRESH_GAUSSIAN_C,
                                    cv2.THRESH_BINARY_INV,
                                    21, 0)

element = cv2.getStructuringElement(cv2.MORPH_RECT, (3,3)) 
dilated = cv2.dilate(adap_thresh, element, iterations=1)

# blob detection
params = cv2.SimpleBlobDetector_Params()
params.filterByColor = False
params.minThreshold = 65
params.maxThreshold = 93
params.blobColor = 0
params.minArea = 10
params.maxArea = 5000
params.filterByCircularity = False
params.filterByConvexity = False
params.minCircularity =.4
params.maxCircularity = 1

det = cv2.SimpleBlobDetector_create(params)
keypts = det.detect(dilated)

im_with_keypoints = cv2.drawKeypoints(dilated,
                                      keypts,
                                      np.array([]),
                                      (0, 0, 255),
                                      cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

res = cv2.drawKeypoints(img,
                        keypts,
                        np.array([]),
                        (0, 0, 255 ),
                        cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

i = 0
for kp in keypts:
    print("(%f,%f)"%(kp.pt[0],kp.pt[1]))
    i+=1
    cv2.rectangle(res,(int(kp.pt[0]),int(kp.pt[1])),(int(kp.pt[0])+1,int(kp.pt[1])+1),(0,255,0),2)

#cv2.imshow("Keypoints", im_with_keypoints)
cv2.imshow("RES", res)
cv2.waitKey(0)

Output: blob

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2019-05-30 23:28:17 -0600

Seen: 5,153 times

Last updated: Jun 02 '19