Fill Detected Blobs (opencv,python)
I want to fill the detected blobs in my images with white color. This is the code I am using: # Standard imports import cv2 import numpy as np # Read image im = cv2.imread('5.tif'
Solution 1:
Draw keypoints as filled white circles:
img = im.copy()
for x in range(1,len(keypoints)):
img=cv2.circle(img, (np.int(keypoints[x].pt[0]),np.int(keypoints[x].pt[1])), radius=np.int(keypoints[x].size), color=(255), thickness=-1)
Edit: For rectangle or square, then:
for i inrange(1,len(keypoints)):
x,y = np.int(keypoints[i].pt[0]),np.int(keypoints[i].pt[1])
sz = np.int(keypoints[i].size)
if sz > 1:
sz = np.int(sz/2)
# notice there's no boundary check for pt1 and pt2, you have to do that yourself
img = cv2.rectangle(img, (x-sz,y-sz), (x+sz,y+sz), color=(255), thickness=-1)
Post a Comment for "Fill Detected Blobs (opencv,python)"