@@ -28,24 +28,39 @@ the zero-zero index) on the pixel you want to calculate and sum up the pixel val
28
28
the overlapped matrix values. It's the same thing, however in case of large matrices the latter
29
29
notation is a lot easier to look over.
30
30
31
+ Code
32
+ ----
33
+
31
34
@add_toggle_cpp
32
- Now let us see how we can make this happen by using the basic pixel access method or by using the
33
- @ref cv::filter2D function.
35
+ You can download this source code from [ here
36
+ ] ( https://raw.githubusercontent.com/opencv/opencv/master/samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp ) or look in the
37
+ OpenCV source code libraries sample directory at
38
+ ` samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp ` .
39
+ @include samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp
34
40
@end_toggle
35
41
36
42
@add_toggle_java
37
- Now let us see how we can make this happen by using the basic pixel access method or by using the
38
- ** Imgproc.filter2D()** function.
43
+ You can download this source code from [ here
44
+ ] ( https://raw.githubusercontent.com/opencv/opencv/master/samples/java/tutorial_code/core/mat_mask_operations/MatMaskOperations.java ) or look in the
45
+ OpenCV source code libraries sample directory at
46
+ ` samples/java/tutorial_code/core/mat_mask_operations/MatMaskOperations.java ` .
47
+ @include samples/java/tutorial_code/core/mat_mask_operations/MatMaskOperations.java
39
48
@end_toggle
40
49
41
50
@add_toggle_python
42
- Now let us see how we can make this happen by using the basic pixel access method or by using the
43
- ** cv2.filter2D()** function.
51
+ You can download this source code from [ here
52
+ ] ( https://raw.githubusercontent.com/opencv/opencv/master/samples/python/tutorial_code/core/mat_mask_operations/mat_mask_operations.py ) or look in the
53
+ OpenCV source code libraries sample directory at
54
+ ` samples/python/tutorial_code/core/mat_mask_operations/mat_mask_operations.py ` .
55
+ @include samples/python/tutorial_code/core/mat_mask_operations/mat_mask_operations.py
44
56
@end_toggle
45
57
46
58
The Basic Method
47
59
----------------
48
60
61
+ Now let us see how we can make this happen by using the basic pixel access method or by using the
62
+ ** filter2D()** function.
63
+
49
64
Here's a function that will do this:
50
65
@add_toggle_cpp
51
66
@snippet samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp basic_method
@@ -132,37 +147,38 @@ The filter2D function
132
147
Applying such filters are so common in image processing that in OpenCV there exist a function that
133
148
will take care of applying the mask (also called a kernel in some places). For this you first need
134
149
to define an object that holds the mask:
150
+
135
151
@add_toggle_cpp
136
152
@snippet samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp kern
137
-
138
- Then call the @ref cv::filter2D function specifying the input, the output image and the kernel to
139
- use:
140
- @snippet samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp filter2D
141
-
142
- The function even has a fifth optional argument to specify the center of the kernel, a sixth
143
- for adding an optional value to the filtered pixels before storing them in K and a seventh one
144
- for determining what to do in the regions where the operation is undefined (borders).
145
153
@end_toggle
146
154
147
155
@add_toggle_java
148
156
@snippet samples/java/tutorial_code/core/mat_mask_operations/MatMaskOperations.java kern
149
-
150
- Then call the ** Imgproc.filter2D()** function specifying the input, the output image and the kernel to
151
- use:
152
- @snippet samples/java/tutorial_code/core/mat_mask_operations/MatMaskOperations.java filter2D
153
- The function even has a fifth optional argument to specify the center of the kernel, a sixth
154
- for adding an optional value to the filtered pixels before storing them in K and a seventh one
155
- for determining what to do in the regions where the operation is undefined (borders).
156
157
@end_toggle
157
158
158
159
@add_toggle_python
159
160
@snippet samples/python/tutorial_code/core/mat_mask_operations/mat_mask_operations.py kern
161
+ @end_toggle
160
162
161
- Then call the ** cv2. filter2D()** function specifying the input, the output image and the kernell to
163
+ Then call the ** filter2D()** function specifying the input, the output image and the kernel to
162
164
use:
165
+
166
+ @add_toggle_cpp
167
+ @snippet samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp filter2D
168
+ @end_toggle
169
+
170
+ @add_toggle_java
171
+ @snippet samples/java/tutorial_code/core/mat_mask_operations/MatMaskOperations.java filter2D
172
+ @end_toggle
173
+
174
+ @add_toggle_python
163
175
@snippet samples/python/tutorial_code/core/mat_mask_operations/mat_mask_operations.py filter2D
164
176
@end_toggle
165
177
178
+ The function even has a fifth optional argument to specify the center of the kernel, a sixth
179
+ for adding an optional value to the filtered pixels before storing them in K and a seventh one
180
+ for determining what to do in the regions where the operation is undefined (borders).
181
+
166
182
This function is shorter, less verbose and, because there are some optimizations, it is usually faster
167
183
than the * hand-coded method* . For example in my test while the second one took only 13
168
184
milliseconds the first took around 31 milliseconds. Quite some difference.
@@ -172,22 +188,7 @@ For example:
172
188
![ ] ( images/resultMatMaskFilter2D.png )
173
189
174
190
@add_toggle_cpp
175
- You can download this source code from [ here
176
- ] ( https://github.com/opencv/opencv/tree/master/samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp ) or look in the
177
- OpenCV source code libraries sample directory at
178
- ` samples/cpp/tutorial_code/core/mat_mask_operations/mat_mask_operations.cpp ` .
179
-
180
191
Check out an instance of running the program on our [ YouTube
181
192
channel] ( http://www.youtube.com/watch?v=7PF1tAU9se4 ) .
182
193
@youtube {7PF1tAU9se4}
183
194
@end_toggle
184
-
185
- @add_toggle_java
186
- You can look in the OpenCV source code libraries sample directory at
187
- ` samples/java/tutorial_code/core/mat_mask_operations/MatMaskOperations.java ` .
188
- @end_toggle
189
-
190
- @add_toggle_python
191
- You can look in the OpenCV source code libraries sample directory at
192
- ` samples/python/tutorial_code/core/mat_mask_operations/mat_mask_operations.py ` .
193
- @end_toggle
0 commit comments