准备工作:python3.7, pycharm,opencv-python模块。(不懂的话,网上有许多资料可供查询) 全部代码如下(直接可运行,需将图片路径换成自己电脑的图片路径) import cv2 as cv import numpy as np # canny边缘检测 def canny_demo(image): t = 140 canny_output = cv.Canny(image, t, t * 2) cv.imshow("canny_output", canny_output) cv.imwrite("D:\\tupian\canny_out