I'm trying to replace a detected face in an image with a modified one. I have no issue utilizing a regular rectangular roi. However, to be a bit more precise, I'm trying to use a circle ROI. I know you have to create a rectangular mask to do this. Here I am using a black mask. Maybe there is a way to make the mask transparent? I think I'm close, yet when I merge the augmented face onto the image, the modified face portion has the square black border (from the mask i presume) included. How do i eliminate the black square border? Is this possible? Thank you!
See the problem: https://pasteboard.co/JscU9re.png
Here is the relevant code ... let me know if you need all of it.
int radius = faces[ic].width / 2;
Mat mask(Size(faces[ic].width,faces[ic].height), CV_8U, Scalar(0)); // all black
Rect region = Rect(faces[ic].x,faces[ic].y,faces[ic].width,faces[ic].height);
Mat circ_roi;
Mat roi(img,region);
Mat insetImage(img, region);
circle(mask, Point(radius,radius), radius, Scalar(255), -1);
bitwise_and(roi, roi, circ_roi, mask); // retain only pixels inside the circle
// create a mat to store the modified mat from the gpu
Mat h_result (circ_roi.size(), circ_roi.type());
// create GPU/device images, same size and type as original host image
cuda::GpuMat d_crop(circ_roi);
cuda::GpuMat d_result;
// create the gaussian filter
cv::Ptr<cuda::Filter> gauss = cv::cuda::createGaussianFilter(d_crop.type(),
d_result.type(), Size(ksize, ksize), 6.0, 6.0);
// apply the gaussian filter to our cropped image
gauss->apply(d_crop, d_result);
// download the result image from device to host
d_result.download(h_result);
// leaves the black border around circle :(
h_result.copyTo(insetImage);
Thank you, Chris