1
1
# -*- coding: utf-8 -*-
2
2
3
+ '''
4
+ 2D 卷积
5
+ OpenCV 提供的函数 cv.filter2D() 可以 我们对一幅图像 卷积操
6
+ 作。
7
+ 操作如下 将核放在图像的一个像素 A 上 求与核对应的图像上 25 5x5 个像素的和 在取平均数 用 个平均数替代像素 A 的值。 复以上操作直到 将图像的每一个像素值 更新一 。
8
+ '''
9
+
3
10
import cv2
4
11
import numpy as np
5
12
from matplotlib import pyplot as plt
6
- img = cv2 .imread ('opencv_logo.png' )
7
- kernel = np .ones ((5 ,5 ),np .float32 )/ 25
8
- #cv.Filter2D(src, dst, kernel, anchor=(-1, -1))
9
- #ddepth –desired depth of the destination image;
10
- #if it is negative, it will be the same as src.depth();
11
- #the following combinations of src.depth() and ddepth are supported:
12
- #src.depth() = CV_8U, ddepth = -1/CV_16S/CV_32F/CV_64F
13
- #src.depth() = CV_16U/CV_16S, ddepth = -1/CV_32F/CV_64F
14
- #src.depth() = CV_32F, ddepth = -1/CV_32F/CV_64F
15
- #src.depth() = CV_64F, ddepth = -1/CV_64F
16
- #when ddepth=-1, the output image will have the same depth as the source.
17
13
18
- dst = cv2 .filter2D (img ,- 1 ,kernel )
19
- plt .subplot (121 ),plt .imshow (img ),plt .title ('Original' )
14
+ img = cv2 .imread ('../data/opencv_logo.png' )
15
+ kernel = np .ones ((5 , 5 ), np .float32 ) / 25
16
+ # cv.Filter2D(src, dst, kernel, anchor=(-1, -1))
17
+ # ddepth –desired depth of the destination image;
18
+ # if it is negative, it will be the same as src.depth();
19
+ # the following combinations of src.depth() and ddepth are supported:
20
+ # src.depth() = CV_8U, ddepth = -1/CV_16S/CV_32F/CV_64F
21
+ # src.depth() = CV_16U/CV_16S, ddepth = -1/CV_32F/CV_64F
22
+ # src.depth() = CV_32F, ddepth = -1/CV_32F/CV_64F
23
+ # src.depth() = CV_64F, ddepth = -1/CV_64F
24
+ # when ddepth=-1, the output image will have the same depth as the source.
25
+
26
+ dst = cv2 .filter2D (img , - 1 , kernel )
27
+
28
+ plt .subplot (121 ), plt .imshow (img ), plt .title ('Original' )
20
29
plt .xticks ([]), plt .yticks ([])
21
- plt .subplot (122 ),plt .imshow (dst ),plt .title ('Averaging' )
30
+ plt .subplot (122 ),plt .imshow (dst ),plt .title ('Averaging' )
22
31
plt .xticks ([]), plt .yticks ([])
23
32
24
- plt .show ()
33
+ plt .show ()
0 commit comments