糖尿病康复,内容丰富有趣,生活中的好帮手!
糖尿病康复 > canny边缘检测 阈值调整

canny边缘检测 阈值调整

时间:2019-12-16 11:34:22

相关推荐

canny边缘检测 阈值调整

此实时监测的代码为转载,原网址我忘了,如果原作者看到请联系我

canny函数原型:

输入值依次为原图,阈值1,阈值2返回值为包含边缘的二值图

具体请看:/sunny2038/article/details/9202641

edge = cv2.Canny(image, threshold1, threshold2[, edges[, apertureSize[, L2gradient ]]])

代码运行后会有一个横条实时更改canny函数中的阈值从而观测图片状态

import cv2import numpy as npdef CannyThreshold(lowThreshold):detected_edges = cv2.GaussianBlur(gray,(3,3),0)detected_edges = cv2.Canny(detected_edges,lowThreshold,lowThreshold*ratio,apertureSize = kernel_size)dst = cv2.bitwise_and(img,img,mask = detected_edges) # just add some colours to edges from original image.cv2.imshow('canny demo',dst)lowThreshold = 0max_lowThreshold = 100ratio = 3kernel_size = 3img = cv2.imread('82.png')gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)img = cv2.GaussianBlur(img,(3,3),0)cv2.namedWindow('canny demo')cv2.createTrackbar('Min threshold','canny demo',lowThreshold, max_lowThreshold, CannyThreshold)CannyThreshold(0) # initializationif cv2.waitKey(0) == 27:cv2.destroyAllWindows()

左图为原图,右图为阈值为0时的边缘检测

左图为原图,右图为阈值为50时的边缘检测

如果觉得《canny边缘检测 阈值调整》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。