OpenCV threshold with mask

In general, you can simply compute the threshold using cv::threshold, and then copy the src image on dst using the inverted mask. // Apply cv::threshold on all image thresh = cv::threshold(src, dst, thresh, maxval, type); // Copy original image on inverted mask src.copyTo(dst, ~mask); With THRESH_OTSU, however, you also need to compute the threshold value … Read more

Serializing OpenCV Mat_

The earlier answers are good, but they won’t work for non-continuous matrices which arise when you want to serialize regions of interest (among other things). Also, it is unnecessary to serialize elemSize() because this is derived from the type value. Here’s some code that will work regardless of continuity (with includes/namespace) #pragma once #include <boost/archive/text_oarchive.hpp> … Read more