当前位置:   article > 正文

opencv提取中心线坐标点算法(python)

opencv提取中心线

opencv结合gis,根据提取中心线坐标点方法

请添加图片描述
请添加图片描述

核心思路

一、通过opencv方法提取骨线,
二、通过骨线,提取每个线的像素坐标
三、循环每个点根据距离连接
循环思路:
1、寻找一个点的八个方向,确定点存在数组里面,就放入线中
请添加图片描述
2、交点处,在交点位置就新建一个线,通过读取一种条线在接着往下寻找点,没有读取的线存在数组中,当一条线到头后,在数组读取下一个节点,只到数组不存在数据,整个过程跑完。
请添加图片描述

代码部分

def point_to_line(centerline):
    """
    点连成线
    :param centerline: 坐标点集
    :return: 返回线集合
    """
    centerline = centerline.tolist()
    point_s = []
    point_conpy = []

    line = []
    for c in centerline:
        if str(line).find(str(c)) == -1:
            point = c
            line_1 = [c]
            while True:
                p = []
                for x in range(point[0] - 1, point[0] + 2):
                    for y in range(point[1] - 1, point[1] + 2):
                        if [x, y] in centerline and [x, y] != point and [x, y] != line_1[len(line_1)-2]:
                            p.append([x, y])
                if len(p) > 1:
                    if len(line_1) > 1:
                        line.append(line_1)
                    for al in p:
                        if str(point_conpy).find(str([al, point])) == -1 and str(point_conpy).find(str([ point, al])) ==-1:
                            point_conpy.append([point, al])
                            point_s.append([point, al])
                    if len(point_s) == 0:
                        point_s.append([point, p[0]])
                    line_1 = point_s[0]
                    point_s = point_s[1:]
                    point = line_1[1]
                if len(p) == 1:
                    line_1.append(p[0])
                    point = p[0]
                if len(p) == 0:
                    if len(line_1) > 1:
                        line.append(line_1)
                    if len(point_s) == 0:
                        break
                    else:
                        line_1 = point_s[0]
                        point_s = point_s[1:]
                        point = line_1[1]
    line_c = []
    for l in line:
        if (l in line_c) is False and (l[::-1] in line_c) is False:
            if len(l) > 0:
                line_c.append(l)
    return line_c
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51

效果展示

请添加图片描述

请添加图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/天景科技苑/article/detail/746799
推荐阅读
相关标签
  

闽ICP备14008679号