Object detection using openCV and python

I am trying to detect white dots in the following image using OpenCV and Python.

enter image description here

I tried using the cv2.HoughCircles function, but without any success.

Do I need to use a different method?

This is my code:

import cv2, cv
import numpy as np
import sys

if len(sys.argv)>1:
    filename = sys.argv[1]
else:
    filename = 'p.png'

img_gray = cv2.imread(filename,cv2.CV_LOAD_IMAGE_GRAYSCALE)

if img_gray==None:
    print "cannot open ",filename

else:
    img = cv2.GaussianBlur(img_gray, (0,0), 2)
    cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
    circles = cv2.HoughCircles(img,cv2.cv.CV_HOUGH_GRADIENT,4,10,param1=200,param2=100,minRadius=3,maxRadius=100)
if circles:
    circles = np.uint16(np.around(circles))
    for i in circles[0,:]:
        cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),1) 
        cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)   

cv2.imshow('detected circles',cimg)
cv2.waitKey(0)
cv2.destroyAllWindows()
+3
source share
3 answers

If you can reproduce the morphological reconstruction in OpenCV, you can easily build an h-dome transformation that will greatly simplify the task. Otherwise, a simple threshold is sufficient for Gaussian filtering.

enter image description here

Binarize[FillingTransform[GaussianFilter[f, 2], 0.4, Padding -> 1]]

Gaussian filtering was performed in the code above in order to effectively suppress noise around the input boundary that would remain after the h-dome conversion otherwise.

(Binarize[GaussianFilter[f, 2], 0.5]), , Kapur (. " " ( , 1985 )):

enter image description hereenter image description here

( ), . 3 OpenCV .

+1

, . 3x3 7x7. - () . HoughCircles, .

0

(, Otsu). , , , .

0

All Articles