Best way to set image region to zeros in OpenCV C++?

c++, opencv

Solution

I would use `setTo()`, for example:

// load an image
cv::Mat pImage = cv::imread("someimage.jpg", CV_LOAD_IMAGE_COLOR);

// select a region of interest
cv::Mat pRoi = pImage(cv::Rect(10, 10, 20, 20));

// set roi to some rgb colour   
pRoi.setTo(cv::Scalar(blue, green, red));

Problem

I would like to ask which is the most efficient way to set a region of a grayscale Mat image to zeros (or any other constant value, for that matter). Should I create a zeros image and then use `copyTo()` or is there a better way?

Original source