Drawing a circle of defined coordinates over edges detected

74 Views Asked by At

Currently, I have a code that detects the edges of an image using canny. But I want to draw circle over the edges detected and the circles shouldn't overlap with each other. If I have 1000 edges detected and I want to draw a circle of radius 5 over all edges I want the program to draw a circle for edges that are equal to or greater than the distance 5 appart so I won't have overlapping circles.

import cv2
import numpy as np

img = cv2.imread('dred.jpg', 0)

edges = cv2.Canny(img, 100, 255) 

indices = np.where(edges != [0])
coordinates = (indices[0], indices[1])
xx=[p for p in indices[0]]
yy=[q for q in indices[1]]
#from here i'm going to measure the distance of each edge using d=((x_[i]-x_[i-1])^2-(y[i]-y[i-1])^2)^1/2

rrr = [a - b for a, b in zip(xx, xx[1:] + [xx[0]])]
yyy = [a - b for a, b in zip(yy, yy[1:] + [yy[0]])]
#rrr gives me the difference of two consequative x values in our list of x coordinate
#yyy gives me the difference of two consequative y values in our list of y coordinate
for i in range(len(indices[0])):
    r=(rrr[i]**2+yyy[i]**2)**(1/2)
    #print(r)  #prints distance of each edges detected
for x, y in zip(indices[0], indices[1]):
    T=(y, x)
    cv2.circle(edges, T, 5, (255, 255, 255), 1) #draws circle over each edges detected cv2.imshow('edges', edges) 
cv2.imshow("window", edges)
cv2.waitKey(0) 
cv2.destroyAllWindows()

Here I have a code that measures the distance between two edges detected near by and I have also a code that draws a circle of radius 5 on each edge detected but I want to define coordinate of the circle based on the radius and distance of each edges. The circle should not overlap which means the coordinate of the circle should be bounded by the distance and radius defined. Here my original image I used This is the image I used This is what i currently have and as you can see the circles are overlapping so much that you don't see any circle. And This is what i currently have and as you can see the circles are overlapping so much that you don't see any circle.

I don't know how to proceed from here. Thank you!

0

There are 0 best solutions below