#Solving maze with morphological transformation
"""
usage:Solving maze with morphological transformation
needed module:cv2/numpy/sys
ref:
1.http://www.mazegenerator.net/
2.http://blog.leanote.com/post/leeyoung/539a629aab35bc44e2000000
@author:Robin Chen
"""
import cv2
import numpy as np
import sys
def SolvingMaze(image):
#load an image
try:
img = cv2.imread(image)
except Exception,e:
print 'Error:can not open the image!'
sys.exit()
#show image
#cv2.namedWindow('image', cv2.WINDOW_NORMAL)
cv2.imshow('maze_image',img)
#convert to gray
gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
#show gray image
#cv2.imshow('gray_image',gray_image)
#convert to binary image
retval,binary_image = cv2.threshold(gray_image, 10,255, cv2.THRESH_BINARY_INV)
#cv2.imshow('binary_image',binary_image)
contours,hierarchy = cv2.fi
python 使用分水岭算法实现走迷宫
最新推荐文章于 2024-09-10 16:47:25 发布
本文介绍了一种使用Python、OpenCV和NumPy来解决迷宫的方法。通过将图像转换为灰度、二值化,然后利用分水岭算法找到迷宫的路径。最终,通过膨胀和腐蚀操作确定路径,并在原始图像上显示解决方案。
摘要由CSDN通过智能技术生成