OpenCV python 图像梯度--sobel图像处理

你说的曾经没有我的故事 提交于 2020-01-13 04:37:53

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]
在这里插入图片描述

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!