Я работаю над обнаружением кругов, чтобы найти круги двух разных размеров, поэтому у меня есть круги размером 58 пикселей и размером 64 пикселя (это кажется не таким уж большим, но поверьте мне, это так!!).
Мне бы хотелось, чтобы функция cv2.HoughCircles либо принимала ненепрерывный интервал [r1,r2] ,[r3,r4], либо возвращала метрику, например интенсивность или ширину изображения в массиве аккумуляторов. , чтобы я мог установить лучший рабочий радиус для каждого круга.
Если opencv HoughCircle не лучший инструмент для того, что я рассматриваю, я мог бы также использовать что-то еще, например RANSAC
Я пытался указать только диапазон [r1,r4], но, поскольку я смотрю на трехмерный объект в искривленном пространстве, я получаю очень большое распределение диаметров, если использую эти границы.
Я также фильтрую ложные срабатывания по яркости:
def remove_low_lum(img, x_circles, y_circles, R_circles = None, R_filter = 10 , lum_min_remove = 50, **kwargs):
'''Removes the false positives after hough circle detection. Checks the
median luminosity around the centers detected by HoughCircles.
-------
img: base img
x_circles, y_circles: coordinates of the centers
R_filter: length of the square on which the luminosity is checked
lum_min_remove: threshold for beads removal. If median(lum) < lum_min_remove,
the bead is removed
'''
to_remove = []
for i in range(len(x_circles)):
xc,yc = int(x_circles), int(y_circles) #no need to worry about ceil or floor, 0.5 pixel is no big deal
xl,xh,yl,yh = max(0,xc - R_filter), max(0,xc + R_filter), max(0,yc - R_filter), max(0,yc + R_filter)
to_check = img[yl:yh, xl:xh].flatten()
lum_circ = np.median(to_check)
if lum_circ < lum_min_remove: #if the lumi is to low, delete
to_remove +=
if type(R_circles) == type(None):
return np.delete(x_circles, to_remove), np.delete(y_circles, to_remove)
else:
return np.delete(x_circles, to_remove), np.delete(y_circles, to_remove), np.delete(R_circles, to_remove)
def corrected_hough(img, h_param1 = 100, h_param2 = 1, min_dist = 45, min_rad = 22, max_rad = 30,
correct = True, radii = False, **kwargs):
'''OPENCV's HoughCircles transform with correction. By default, only removes false
positives based on luminosity tests. More advanced features (filling) are
available in corrected_hough and filter_and_fill modules, and might be implemented here in the future.
----
'''
if len(img.shape) > 2:
img = img[:,:,1]
# Perform houghcircle detection
hough = cv2.HoughCircles(img, cv2.HOUGH_GRADIENT, 1,min_dist,
param1=h_param1, param2=h_param2, minRadius=min_rad,
maxRadius=max_rad)
circles = hough[0]
x_circles = circles[:,0]
y_circles = circles[:,1]
R_circles= circles[:,2]
# Output without correction if wanted
if correct == False:
if radii: # To output the circles radii
return x_circles, y_circles, R_circles
else:
return x_circles, y_circles
if correct: # Output with correction. (radii not implemented yet)
if radii:
x_f, y_f, R_f = remove_low_lum(img, x_circles,
y_circles, R_circles = R_circles, **kwargs)
return x_f, y_f, R_f
else:
x_f, y_f = remove_low_lum(img, x_circles, y_circles, **kwargs)
return x_f, y_f
Подробнее здесь: https://stackoverflow.com/questions/785 ... cle-opencv
Круг Хафа opencv ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Повышение точности линии Хафа/сегментация корешков книг с помощью OpenCV и C++
Anonymous » » в форуме C++ - 0 Ответы
- 16 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Алгоритм преобразования Хафа для распознавания образов прямых линий из точек
Anonymous » » в форуме Python - 0 Ответы
- 13 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Алгоритм преобразования Хафа для распознавания образов прямых линий из точек
Anonymous » » в форуме Python - 0 Ответы
- 7 Просмотры
-
Последнее сообщение Anonymous
-