小编Yok*_*olt的帖子

如何在镂空迷宫图像中找到最短路径?

我正在使用图像处理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(): …
Run Code Online (Sandbox Code Playgroud)

opencv image-processing networkx python-2.7 image-morphology

5
推荐指数
1
解决办法
847
查看次数