Know the radius of the circle using the python cv2 library

Asked

Viewed 56 times

0

I need to find the radius of the circle using the cv2 library, I have the following code:

What he does is circle where he finds circles within the parameters I set, now I want to know the radius of each circle, how can I do? I found absolutely NOTHING in the opencv documentation about this

import scipy.ndimage
import skimage.io
import matplotlib.pyplot as plt
import cv2
from google.colab.patches import cv2_imshow
import math

img = cv2.imread('/content/image.tif',0)

# Set up the SimpleBlobdetector with default parameters.
params = cv2.SimpleBlobDetector_Params()

# Define thresholds
#Can define thresholdStep. See documentation. 
params.minThreshold = 0
params.maxThreshold = 255

# Filter by Area.
params.filterByArea = True
params.minArea = 1
params.maxArea = 10000

# 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 InertiaRatio (define a precisao que irá circular o circulo)
params.filterByInertia = True
params.minInertiaRatio = 0
params.maxInertiaRatio = 1

# Distance Between Blobs
params.minDistBetweenBlobs = 0

# Setup the detector with parameters
detector = cv2.SimpleBlobDetector_create(params)

# Detect blobs
keypoints = detector.detect(img)

print("Number of blobs detected are : ", len(keypoints))

# Draw blobs
img_with_blobs = cv2.drawKeypoints(img, keypoints, np.array([]), (255,0,0), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)

cv2_imshow(img_with_blobs)

cv2.waitKey(0)
cv2.destroyAllWindows()```


No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.