OpenCV python 图像梯度–sobel图像处理
处理原图:[source.jpg]
import cv2
def main():
# 1.导入图片
img_src = cv2.imread("source.jpg")
# 2.执行sobel算法1
img_sobel_64x = cv2.Sobel(img_src, cv2.CV_64F, 0, 1)
img_sobel_64y = cv2.Sobel(img_src, cv2.CV_64F, 1, 0)
img_sobel_x = cv2.convertScaleAbs(img_sobel_64x)
img_sobel_y = cv2.convertScaleAbs(img_sobel_64y)
img_sobel = cv2.addWeighted(img_sobel_x, 0.5, img_sobel_y, 0.5, 0)
# 2.执行sobel算法2
img_sobelxy_11 = cv2.Sobel(img_src, cv2.CV_64F, 1, 1)
img_sobelxy_11 = cv2.convertScaleAbs(img_sobelxy_11)
# 3.显示图片
cv2.imshow("img_src", img_src)
cv2.imshow("img_sobel", img_sobel)
cv2.imshow("img_sobelxy_11", img_sobelxy_11)
cv2.waitKey()
cv2.destroyAllWindows()
if __name__ == '__main__':
main()
结果图片:[img_sobel.jpg]
结果图片:[img_sobelxy_11.jpg]