Images can be combined in different ways. Since they are regular matrices, they can be added, subtracted, multiplied, or divided. OpenCV offers various image arithmetic operators, and their use is discussed in this recipe.
Let's work with a second image that we will combine to our input image using an arithmetic operator. The following represents this second image:
Here, we add two images. This is useful when we want to create some special effects or to overlay information over an image. We do this by calling the cv::add
function, or more precisely here, the cv::addWeighted
function, since we want a weighted sum as follows:
cv::addWeighted(image1,0.7,image2,0.9,0.,result);
The operation results in a new image, as seen in the following screenshot: