O'Reilly logo

Learning Image Processing with OpenCV by Gloria Bueno García, Oscar Deniz Suarez, José Luis Espinosa Aranda, Jesus Salido Tercero, Ismael Serrano Gracia, Noelia Vállez Enano

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Arithmetic operations

Arithmetic operators are overloaded. This means that we can operate on Mat images like we can in this example:

imgblend = 0.2*img1 + 0.8*img2;

In OpenCV, the result value of an operation is subject to the so-called saturation arithmetic. This means that the final value is actually the nearest integer in the 0..255 range.

Bitwise operations bitwise_and(), bitwise_or(), bitwise_xor(), and bitwise_not() can be very useful when working with masks. Masks are binary images that indicate the pixels in which an operation is to be performed (instead of the whole image). The following bitwise_and example shows you how to use the AND operation to crop part of an image:

#include <opencv2/opencv.hpp> using namespace cv; using namespace std; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required