According to the following ideas, you can use hsv to extract the required area and put it in the Mask for matting.
#include<iostream>
#include<opencv2/opencv.hpp>
#include<opencv2/highgui.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat src=imread("/home/sms/tu/1.jpg"),src1;
Rect r=Rect(150,150,150,150);
Mat mask(src.size(),CV_8UC3,Scalar(0,0,0));
rectangle(mask,r,Scalar(255,255,255),-1);
bitwise_and(src,mask,src1);
imshow("src",src);
imshow("mask",mask);
imshow("src1",src1);
waitKey(0);
}