python屏幕找图算法_python-2.7 – 如何在镂空迷宫图像中找到最短路径?

我正在使用图像处理和NetworkX搜索算法进行迷宫解决,需要找到这些线上两点之间的最短连接路径.

#Solving Maze Using Image Processing and NetWorkx search

#Open Maze image

img = cv2.imread("C:/Users/Dell/HandMadeMaze1.jpg")

kernel = np.ones((1,1),np.uint8)

#Convert to GrayScaledImage

grayscaled = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

#B?naryThreshold + OtsuThreshold + BinaryThreshold

retval, threshold = cv2.threshold(grayscaled, 10, 255, cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU)

retval, threshold2 = cv2.threshold(threshold, 10, 255, cv2.THRESH_BINARY_INV)

threshold2[threshold2 == 255] = 1

#Skeletonize the Thresholded Image

skel = skeletonize(threshold2)

#Build Graph from skeleton

graph = sknw.build_sknw(skel, multi=False)

G = nx.Graph(graph)

plt.imshow(img, cmap='gray')

#Draw Edges by 'pts'

for (s,e) in graph.edges():

ps = graph[s][e]['pts']

plt.plot(ps[:,1], ps[:,0], 'red')

#Draw Node by 'o'

node, nodes = graph.node, graph.nodes()

ps = np.array([node[i]['o'] for i in nodes])

plt.plot(ps[:,1], ps[:,0], 'g.')

plt.title('Skeletonize')

plt.savefig('Overlay_Maze.jpg')

plt.show()

G = nx.path_graph(len(ps))

G = nx.karate_club_graph()

pos = nx.spring_layout(G)

nx.draw(G,pos,node_color='b')

当我运行上面的代码时,我得到以下输出.

原始输入迷宫图像:

?? –

处理完图像后:

? –

X-Y坐标上的节点:

? –

路径信息:

我可以成功执行图像处理操作,但搜索算法可以找到两个节点之间最短的鸟类飞行距离.我想找到沿着Skeleton的最短路径.

当我正在研究这个github repo时,我看到我使用NetworkX库解决了这个问题,但我无法解决它,因为它没有给出任何细节.

如何使用图像处理和任何搜索算法找到迷宫图像骨架的最短路径?

提前致谢.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值