Skip to content

Commit bc09d1b

Browse files
committed
Merge pull request opencv#9406 from Cartucho:update_core_tutorials
2 parents f1aa180 + 45afd29 commit bc09d1b

File tree

16 files changed

+1128
-286
lines changed

16 files changed

+1128
-286
lines changed

doc/tutorials/core/adding_images/adding_images.markdown

Lines changed: 69 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
Adding (blending) two images using OpenCV {#tutorial_adding_images}
22
=========================================
33

4+
@prev_tutorial{tutorial_mat_operations}
5+
@next_tutorial{tutorial_basic_linear_transform}
6+
47
Goal
58
----
69

710
In this tutorial you will learn:
811

912
- what is *linear blending* and why it is useful;
10-
- how to add two images using @ref cv::addWeighted
13+
- how to add two images using **addWeighted()**
1114

1215
Theory
1316
------
@@ -28,33 +31,83 @@ eh?)
2831
Source Code
2932
-----------
3033

34+
@add_toggle_cpp
3135
Download the source code from
32-
[here](https://github.com/opencv/opencv/tree/master/samples/cpp/tutorial_code/core/AddingImages/AddingImages.cpp).
36+
[here](https://raw.githubusercontent.com/opencv/opencv/master/samples/cpp/tutorial_code/core/AddingImages/AddingImages.cpp).
3337
@include cpp/tutorial_code/core/AddingImages/AddingImages.cpp
38+
@end_toggle
39+
40+
@add_toggle_java
41+
Download the source code from
42+
[here](https://raw.githubusercontent.com/opencv/opencv/master/samples/java/tutorial_code/core/AddingImages/AddingImages.java).
43+
@include java/tutorial_code/core/AddingImages/AddingImages.java
44+
@end_toggle
45+
46+
@add_toggle_python
47+
Download the source code from
48+
[here](https://raw.githubusercontent.com/opencv/opencv/master/samples/python/tutorial_code/core/AddingImages/adding_images.py).
49+
@include python/tutorial_code/core/AddingImages/adding_images.py
50+
@end_toggle
3451

3552
Explanation
3653
-----------
3754

38-
-# Since we are going to perform:
55+
Since we are going to perform:
56+
57+
\f[g(x) = (1 - \alpha)f_{0}(x) + \alpha f_{1}(x)\f]
58+
59+
We need two source images (\f$f_{0}(x)\f$ and \f$f_{1}(x)\f$). So, we load them in the usual way:
60+
@add_toggle_cpp
61+
@snippet cpp/tutorial_code/core/AddingImages/AddingImages.cpp load
62+
@end_toggle
63+
64+
@add_toggle_java
65+
@snippet java/tutorial_code/core/AddingImages/AddingImages.java load
66+
@end_toggle
67+
68+
@add_toggle_python
69+
@snippet python/tutorial_code/core/AddingImages/adding_images.py load
70+
@end_toggle
71+
72+
We used the following images: [LinuxLogo.jpg](https://raw.githubusercontent.com/opencv/opencv/master/samples/data/LinuxLogo.jpg) and [WindowsLogo.jpg](https://raw.githubusercontent.com/opencv/opencv/master/samples/data/WindowsLogo.jpg)
73+
74+
@warning Since we are *adding* *src1* and *src2*, they both have to be of the same size
75+
(width and height) and type.
76+
77+
Now we need to generate the `g(x)` image. For this, the function **addWeighted()** comes quite handy:
78+
79+
@add_toggle_cpp
80+
@snippet cpp/tutorial_code/core/AddingImages/AddingImages.cpp blend_images
81+
@end_toggle
3982

40-
\f[g(x) = (1 - \alpha)f_{0}(x) + \alpha f_{1}(x)\f]
83+
@add_toggle_java
84+
@snippet java/tutorial_code/core/AddingImages/AddingImages.java blend_images
85+
@end_toggle
4186

42-
We need two source images (\f$f_{0}(x)\f$ and \f$f_{1}(x)\f$). So, we load them in the usual way:
43-
@snippet cpp/tutorial_code/core/AddingImages/AddingImages.cpp load
87+
@add_toggle_python
88+
@snippet python/tutorial_code/core/AddingImages/adding_images.py blend_images
89+
Numpy version of above line (but cv2 function is around 2x faster):
90+
\code{.py}
91+
dst = np.uint8(alpha*(img1)+beta*(img2))
92+
\endcode
93+
@end_toggle
4494

45-
**warning**
95+
since **addWeighted()** produces:
96+
\f[dst = \alpha \cdot src1 + \beta \cdot src2 + \gamma\f]
97+
In this case, `gamma` is the argument \f$0.0\f$ in the code above.
4698

47-
Since we are *adding* *src1* and *src2*, they both have to be of the same size (width and
48-
height) and type.
99+
Create windows, show the images and wait for the user to end the program.
100+
@add_toggle_cpp
101+
@snippet cpp/tutorial_code/core/AddingImages/AddingImages.cpp display
102+
@end_toggle
49103

50-
-# Now we need to generate the `g(x)` image. For this, the function @ref cv::addWeighted comes quite handy:
51-
@snippet cpp/tutorial_code/core/AddingImages/AddingImages.cpp blend_images
52-
since @ref cv::addWeighted produces:
53-
\f[dst = \alpha \cdot src1 + \beta \cdot src2 + \gamma\f]
54-
In this case, `gamma` is the argument \f$0.0\f$ in the code above.
104+
@add_toggle_java
105+
@snippet java/tutorial_code/core/AddingImages/AddingImages.java display
106+
@end_toggle
55107

56-
-# Create windows, show the images and wait for the user to end the program.
57-
@snippet cpp/tutorial_code/core/AddingImages/AddingImages.cpp display
108+
@add_toggle_python
109+
@snippet python/tutorial_code/core/AddingImages/adding_images.py display
110+
@end_toggle
58111

59112
Result
60113
------

0 commit comments

Comments
 (0)