使用Sobel算子进行图像水平或者垂直方向边缘检测,比较简单,直接附上代码:
import cv2import skimagefrom skimage import io,data,color,filtersimport matplotlib.pyplot as pltif __name__ == "__main__":#图片路径img_path = "fault1.jpg"img = skimage.io.imread(img_path,as_gray=True)#垂直方向边缘检测edgev = skimage.filters.sobel_v(img)#水平方向边缘检测#edgev = filters.sobel_h(img)img = edgev * 255#乘以255是为了保存图片plt.imshow(edgev,plt.cm.gray)plt.show()cv2.imwrite('bianyuan.jpg', img)