From b2b70a0520a5caa02ddbe596e54093960221453e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Python=E5=B0=8F=E7=99=BD=E8=BF=9B=E9=98=B6?= <860365566@qq.com> Date: Fri, 10 Dec 2021 13:28:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=B0=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../4.\346\242\257\345\272\246/Gradient.py" | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 "data/1.OpenCV\345\210\235\351\230\266/3.\345\233\276\345\203\217\345\242\236\345\274\272\345\222\214\346\273\244\346\263\242/4.\346\242\257\345\272\246/Gradient.py" diff --git "a/data/1.OpenCV\345\210\235\351\230\266/3.\345\233\276\345\203\217\345\242\236\345\274\272\345\222\214\346\273\244\346\263\242/4.\346\242\257\345\272\246/Gradient.py" "b/data/1.OpenCV\345\210\235\351\230\266/3.\345\233\276\345\203\217\345\242\236\345\274\272\345\222\214\346\273\244\346\263\242/4.\346\242\257\345\272\246/Gradient.py" new file mode 100644 index 0000000..f56af2d --- /dev/null +++ "b/data/1.OpenCV\345\210\235\351\230\266/3.\345\233\276\345\203\217\345\242\236\345\274\272\345\222\214\346\273\244\346\263\242/4.\346\242\257\345\272\246/Gradient.py" @@ -0,0 +1,14 @@ +import cv2 as cv + +if __name__ == '__main__': + img = cv.imread("lena.png", flags=1) + imgGray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) + + SobelX = cv.Sobel(imgGray, cv.CV_16S, 1, 0) # 计算 x 轴方向 + SobelY = cv.Sobel(imgGray, cv.CV_16S, 0, 1) # 计算 y 轴方向 + absX = cv.convertScaleAbs(SobelX) # 转回 uint8 + absY = cv.convertScaleAbs(SobelY) # 转回 uint8 + SobelXY = cv.addWeighted(absX, 0.5, absY, 0.5, 0) # 用绝对值近似平方根 + + cv.imshow("Sobel gradient", SobelXY) + cv.waitKey(0) \ No newline at end of file -- GitLab