Friday, 16 June 2023

Removing Noise and Detecting Circle in Spotlight Using OpenCV

I have been trying to detect circles in spotlight images using OpenCV and have a variety of pictures I am working with, generally looking something like these 4 images:

enter image description here enter image description here enter image description here enter image description here

Following some image processing (using a threshold, blurring) I have gotten the images to look something like this: enter image description here

However, trying to use the HoughCircles function, even after playing around with it for a while seems to not work. Is there something that I am glossing over while using Hough Cicles, or is there a better way to detect the circles than using HoughCircles?

My current code:

import cv2 as cv 
import numpy as np 

img = cv.imread('image.jpg', cv.IMREAD_GRAYSCALE)
img = cv.medianBlur(img,33)
assert img is not None, "file could not be read, check with os.path.exists()"
image = cv.adaptiveThreshold(img,255,cv.ADAPTIVE_THRESH_GAUSSIAN_C,\
            cv.THRESH_BINARY,73,2)
blur = cv.blur(image,(5,5))
circles = cv.HoughCircles(blur,cv.HOUGH_GRADIENT,1,20,
                            param1=50,param2=30,minRadius=30)
circles = np.uint16(np.around(circles))
for i in circles[0,:]:
    # draw the outer circle
    cv.circle(circles,(i[0],i[1]),i[2],(0,255,0),2)
    # draw the center of the circle
    cv.circle(circles,(i[0],i[1]),2,(0,0,255),3)

cv.imshow('Objects Detected',blur)
cv.waitKey(0)


from Removing Noise and Detecting Circle in Spotlight Using OpenCV

No comments:

Post a Comment