Figure 5-4: Results of varying the threshold type in cv::threshold(); the horizontal line through each
chart represents a particular threshold level applied to the top chart and its effect for each of the five types
of threshold operations below
Let’s look at a simple example. In Example 5-1, we sum all three channels of an image and then clip the
result at 100.
Example 5-1: Example code making use of cv::threshold()
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace std;
void sum_rgb( const cv::Mat& src, cv::Mat& dst ) {
// Split image onto the color planes.
vector< cv::Mat> planes;
cv::split(src, planes);
cv::Mat b = planes[0], g = planes[1], r = planes[2], s;
// Add equally weighted rgb values.
cv::addWeighted( r, 1./3., g, 1./3., 0.0, s ...