OPENCV sobel/scharr/laplacian算子检测不同方向边缘信息;
sobel算子检测不同方向边缘信息
import cv2 import numpy as np img=cv2.imread('C:/Users/59925/Desktop/pytest/pics/minions-s.jpg') #获取竖向轮廓 sobelx=cv2.Sobel(img,cv2.CV_64F,1,0,ksize=3) sobelx=cv2.convertScaleAbs(sobelx) #获取横向轮廓 sobely=cv2.Sobel(img,cv2.CV_64F,0,1,ksize=3) sobely=cv2.convertScaleAbs(sobely) #两相加 sobelxy=cv2.addWeighted(sobelx,0.5,sobely,0.5,0) #cv2同时计算两个方向轮廓效果不好 mix=cv2.Sobel(img,cv2.CV_64F,1,1,ksize=3) mix=cv2.convertScaleAbs(mix) res=np.hstack((sobelx,sobely,sobelxy,mix)) cv2.imshow('res',res) cv2.waitKey(0) cv2.destroyAllWindows() #scharr算子 scharrx=cv2.Scharr(img,cv2.CV_64F,1,0) scharrx=cv2.convertScaleAbs(scharrx) scharry=cv2.Scharr(img,cv2.CV_64F,0,1) scharry=cv2.convertScaleAbs(scharry) scharrxy=cv2.addWeighted(scharrx,0.5,scharry,0.5,0) #laplacian 算子 laplacian=cv2.Laplacian(img,cv2.CV_64F) laplacian=cv2.convertScaleAbs(laplacian) res1=np.hstack((scharrx,scharry,scharrxy,laplacian)) cv2.imshow('res1',res1) cv2.waitKey(0) cv2.destroyAllWindows()
sobelx,sobely,sobelxy,mix
scharrx,scharry,scharrxy,laplacian