加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – 测量连续点的曲率

发布时间:2020-12-16 21:37:57 所属栏目:Python 来源:网络整理
导读:我有一个点列表(数量级为数万),我需要使用 python识别两件事: 1-这些点中的连续点组(abs(x2-x1) = 1和abs(y2-y1) = 1) 2-每组的弧度/半径 以下是一组示例: [[331,400],[331,1200],[332,486],522], 655],3800],3877],3944],3963], [332,3992],4050],[333, 5
我有一个点列表(数量级为数万),我需要使用 python识别两件事:

1-这些点中的连续点组(abs(x2-x1)< = 1和abs(y2-y1)< = 1) 2-每组的弧度/半径 以下是一组示例:

[[331,400],[331,1200],[332,486],522],
655],3800],3877],3944],3963],
[332,3992],4050],[333,
560],588],655],700],
[333,[334,
400],558],586],654],
[334,697],
3963],[335,521],
[335,556],585],653],695],
3800],
4050],[336,520],555],584],
[336,651],693],
3944],[337,
[337,554],583],649],692],[338,377],553],582],
[338,647],691],[339,
[339,581],644],
654],690],706],[340,376],552],580],641],
[340,689],713],
3877],[341,
[341,579],
639],688],715],[342,
375],578],
[342,637],717],3858],3925],3954],4011],4107],[343,374],
[343,577],635],642],
687],718],[344,373],576],
[344,633],687],719],[345,372],
[345,575],630],720],[346,370],574],
[346,628],686],721],[347,368],
[347,572],626],
686],[348,366],487],570],
[348,624],[349,364],
[349,568],622],722],[350,362],619],
[350,
3858],
4107],[351,357],
[351,
1200],3819],
3915],3934],
4069],[352,355],
[352,621],3915],4069],[353,353],375],
[353,623],
642],
3992],[354,351],
[354,
625],3877]]

解决方法

这将为您提供群集和 list of angles:
from sklearn.cluster import DBSCAN
from scipy.spatial import distance
from scipy.optimize import curve_fit
import numpy as np,math
data = [[331,522]] #....

def angle(pt1,pt2):
    x1,y1 = pt1
    x2,y2 = pt2
    inner_product = x1*x2 + y1*y2
    len1 = math.hypot(x1,y1)
    len2 = math.hypot(x2,y2)
    return math.acos(inner_product/(len1*len2))

db=DBSCAN(eps=1,min_samples=2,metric='precomputed').fit(
  distance.squareform(distance.pdist(data)))
core_samples = db.core_sample_indices_
labels = db.labels_
n_clusters_ = len(set(labels)) - (1 if -1 in labels else 0)
unique_labels = set(labels)

for k in unique_labels:
    class_members = [index[0] for index in np.argwhere(labels == k)]
    cluster_core_samples = [index for index in core_samples
                            if labels[index] == k]
    curve = np.array([data[index] for index in class_members])
    print k,curve,[angle(p1,p2) for p1,p2 in zip(curve,curve[1:])]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读