首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在点之间画一条线,以便使用python进行比较、绘图和分析

在点之间画一条线,以便使用python进行比较、绘图和分析
EN

Stack Overflow用户
提问于 2018-09-03 14:40:20
回答 1查看 160关注 0票数 1

我想在每个点旁边的白色斑点和绿色矩形之间的每个点上画一条线(绿色的用作参考,而斑点是扭曲的,我想得到它们之间的差异并绘制它(曲面图等)。)

另外,我使用以下代码来检测斑点:

代码语言:javascript
复制
if circles is not None:
    circles = np.round(circles[0,:].astype("int"))
    for (x,y,r) in circles:
        cv2.circle(output2, (x,y),r,(0,255,0),2)

我如何知道每个点的中心,以及如何将它们用作数组/列表?首先,因为根据我所读到的内容,这些是绘制形状所必需的。谢谢

EN

回答 1

Stack Overflow用户

发布于 2018-09-03 18:08:52

这是一个使用scikit-image霍夫变换的解决方案。使用以下代码,您可以检测圆,找到圆心和半径(您可以以相同的方式使用cv2的相应函数):

代码语言:javascript
复制
import numpy as np
import matplotlib.pyplot as plt
from skimage import data, color, io
from skimage.transform import hough_circle, hough_circle_peaks
from skimage.feature import canny
from skimage.draw import circle_perimeter
from skimage.util import img_as_ubyte

image = color.rgb2gray(img_as_ubyte(io.imread('new images/FjOll.png')))
edges = canny(image, sigma=1)
hough_radii = [6] # detect circles of radius 6
hough_res = hough_circle(edges, hough_radii)
# select most prominent 25 circles
accums, cx, cy, radii = hough_circle_peaks(hough_res, hough_radii, total_num_peaks=20)
# Draw circles
fig, ax = plt.subplots(ncols=1, nrows=1, figsize=(10, 4))
image = color.gray2rgb(image)
for center_y, center_x, radius in zip(cy, cx, radii):
    circy, circx = circle_perimeter(center_y, center_x, radius)
    print(center_y, center_x, radius)
    image[circy, circx] = (255, 0, 0)
ax.imshow(image)
plt.show()
## detected circles: (center_y, center_x, radius)
# (171, 103, 6)
# (56, 38, 6)
# (16, 99, 6)
# (141, 128, 6)
# (126, 32, 6)
# (95, 159, 6)
# (120, 90, 6)
# (56, 96, 6)
# (57, 157, 6)
# (120, 158, 6)
# (140, 62, 6)
# (108, 64, 6)
# (77, 64, 6)
# (42, 68, 6)
# (106, 130, 6)
# (73, 128, 6)
# (38, 127, 6)
# (75, 130, 6)
# (88, 38, 6)
# (86, 93, 6)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52144364

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档