def img_sobel_binary(im, blur_sz):
# ??????????????
img_blur = cv2.GaussianBlur(im,blur_sz,0)
if len(img_blur.shape) == 3:
blur_gray = cv2.cvtColor(img_blur,cv2.COLOR_BGR2GRAY)
else:
blur_gray = img_blur
# ??Sobel????
sobelx = cv2.Sobel(blur_gray,cv2.CV_16S,1,0,ksize=3)
abs_sobelx = np.absolute(sobelx)
sobel_8u = np.uint8(abs_sobelx)
img_show_hook("Sobel??", sobel_8u)
# OTSU??????
ret, thd = cv2.threshold(sobel_8u, 0, 255, cv2.THRESH_BINARY+cv2.THRESH_OTSU)
thd_abs = cv2.convertScaleAbs(thd)
bgimg = cv2.addWeighted(thd_abs, 1, 0, 0, 0)
img_show_hook("OTSU????", bgimg)
return bgimg
评论列表
文章目录