如何在骨架迷宫图像中找到最短路径?

编程入门 行业动态 更新时间:2024-10-23 01:57:24
本文介绍了如何在骨架迷宫图像中找到最短路径?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

I am working on maze solving using Image Processing and NetworkX search algroithm and need to find the shortest connecting path between two points on those lines.

#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')

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

When I run the code above, I get the following outputs.

原始输入迷宫图像:

-

处理完图像后:

-

X-Y坐标上的节点点:

Node points on X-Y coordinates:

-

路径信息:

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

I can successfully perform image processing operations, but the search algorithm finds the shortest bird flight distance between two nodes. I want to find the shortest path along the Skeleton.

当我从事此工作时 github存储库显示了我使用NetworkX库,但我无法解决,因为它没有提供任何细节.

When I was working on this github repo showed me solve this problem using the NetworkX library but I can not solve it because it does not give any detail.

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

谢谢.

推荐答案

这是因为您要在此处重新分配对框架化图的引用

It's because you are reassigning you reference to the skeletonized graph here

G = nx.path_graph(len(ps)) G = nx.karate_club_graph()

更多推荐

如何在骨架迷宫图像中找到最短路径?

本文发布于:2023-11-30 11:42:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1649843.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:骨架   最短   迷宫   路径   图像

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!