Q:

OpenCV/ C++ Rectangle mask cannot cover over all the region from the original frame

There is my code and screenshot for creating a mask and it seems strange that the size of mask did not cover over all the original frame. Any tips here please?
    *cap >> frame1;
    Rect roi(100,100,100,100);
    for(int i =0; i<frame1.rows; i++)
    {
        for(int j=0; j<frame1.cols;j++)
        {
            if(!roi.contains(Point(i,j)))
            {
                frame1.at<uchar>(i,j) = 0;
            }
        }
    }

A:

My assumption is that frame1 is a color image and has type CV_8UC3.
Try to create and fill frame1 as frame_gray in this code snippet:
cv::Mat3b frame_color;
*cap >> frame_color;
cv::Mat1b frame_gray;
cv::cvtColor(frame_color, frame_gray, CV_BGR2GRAY)

or if you do not like to change type of frame1 use the following code:
*cap >> frame1;
Rect roi(100,100,100,100);
for(int i =0; i<frame1.rows; i++)
{
    for(int j=0; j<frame1.cols;j++)
    {
        if(!roi.contains(Point(i,j)))
        {
            frame1.at<cv::Vec3b>(i,j) = cv::Vec3b::all(0);
        }
    }
}

or which is MUCH shorter (not tested, but idea should be clear):
*cap >> frame1;
Rect roi(100,100,100,100);
cv::Mat3b color_mask = cv::Mat3b::ones(frame1.size());
color_mask(roi) = cv::Mat3b::zeros(roi.size());
frame1 = frame1.mul(color_mask);

