Performing simple image arithmetic

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.

Getting ready

Let's work with a second image that we will combine with our input image using an arithmetic operator. The following represents this second image:

Getting ready

How to do it...

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, ...

Get OpenCV 3 Computer Vision Application Programming Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.