In the above sample you may have noticed operator, and that’s how all the pixel processing is done in OpenCV. When a result of image operation is 8-bit image with pixel values ranging from 0 to 255, each output pixel value is clipped to this available range:
and the similar rules are applied to 8-bit signed and 16-bit signed and unsigned types. This “saturation” semantics (different from usual C language “wrapping” semantics, where lowest bits are taken, is implemented in every image processing function, from the simple cv::add to cv::cvtColor , cv::resize , cv::filter2D etc. It is not a new feature of OpenCV v2.x, it was there from very beginning. In the new version this special template operator is introduced to simplify implementation of this semantic in your own functions.