Python Forum

Full Version: Circular Object Recognition - Help me, please!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello guys. I'm trying to build a program that can identify the points I marked in the image below. The program is attached. I wanted a way to identify all the circles and count them. I do not know what I can do to get it right Sad Sad Sad Sad

[Image: open?id=0BzyEfdd0_E24OTJzTGRXUlhlRnM]
[Image: open?id=0BzyEfdd0_E24MG16eEdrV3FwMDg]

import cv2
import math
import numpy as np

def remove_repeated(lista):
    l = []
    for i in lista:
        if i not in l:
            l.append(i)
    l.sort()
    return 1

kernel = np.ones((5,5),np.float32)/24

img = cv2.imread('nova.jpg',0)
cv2.rectangle(img,(300,300),(100,100),(0,255,0),0)
crop_img = img[10:5000, 1100:1400]

blur1 = cv2.GaussianBlur(img,(5,5),0)
blur2 = cv2.medianBlur(img,21)
blur3 = cv2.filter2D(img,-1,kernel)


cimg = cv2.cvtColor(img, cv2.COLOR_GRAY2BGR)

circles1 = cv2.HoughCircles(blur1,cv2.HOUGH_GRADIENT,1,20,param1=220,param2=21,minRadius=12,maxRadius=25)
#circles1 = np.around(circles1)

circles2 = cv2.HoughCircles(blur2,cv2.HOUGH_GRADIENT,1,20,param1=180,param2=19,minRadius=7,maxRadius=25)
#circles2 = np.around(circles2)

circles3 = cv2.HoughCircles(blur3,cv2.HOUGH_GRADIENT,1,20,param1=240,param2=20,minRadius=7,maxRadius=27)
#circles3 = np.around(circles3)

count = 0
distancex = 0
distancey = 0
distance = 0
CIRCLES = []
a= 0
b= 0
c=0

if type(circles1) is not type(None):
    for i in circles1 [0,:]:
        a= list(i)
        CIRCLES.append(a)

if type(circles2) is not type(None):
    for i in circles2 [0,:]:
        b = list(i)
        CIRCLES.append(b)

if type(circles3) is not type(None):
    for i in circles3 [0,:]:
        c = list(i)
        CIRCLES.append(c)


for i in CIRCLES:
    for j in CIRCLES:
        distancex = j[0] - i[0]
        distancey = j[1] - i[1]
        distance = (abs(((distancex)**2)+((distancey)**2)))**(1/2)
        distance = math.floor(distance)

        if distance<15 and distance!=0:
            CIRCLES.remove(j)
        if j[2]==0:
            CIRCLES.remove(j)

       # if distancex > 300:
            CIRCLES.remove(j)

remove_repeated(CIRCLES)

for i in CIRCLES:
    count = count+1
    cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
    cv2.circle(cimg,(i[0],i[1]),2,(0,0,255),3)

cv2.namedWindow('nova.jpg', cv2.WINDOW_NORMAL)
cv2.imshow('nova.jpg',cimg)
print(count)
cv2.waitKey(0)
cv2.destroyAllWindows()
(Oct-19-2017, 04:15 AM)vinix123 Wrote: [ -> ]the points I marked in the image below

The images link to a private google drive doc.  The forum has attachments, if the only way to express info is via an image, please attach it.