Is there any way to blur a Mat object in OpenCv (for Android) so that the blur is contained within a Rect object? I am doing a face blurring application and have tried this:
Mat mat = ...; // is initialized properly to 480*640
...
Mat blurred = new Mat();
for (Rect rect : faceDetections.toArray()) {
int xStart = Math.max(0, rect.x);
int yStart = Math.max(0, rect.y);
Imgproc.blur(mat, blurred, new Size(rect.width/2, rect.height/2), new Point(xStart, yStart));
Core.rectangle(blurred, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
new Scalar(0, 255, 0));
}
If I comment out the Imgproc.blur
part then it works correctly by drawing a rectagle around the face. However, when I run it with this line I get the following in the logs:
11-07 17:27:54.100: E/AndroidRuntime(25665): Caused by: CvException [org.opencv.core.CvException: cv::Exception: /hdd2/buildbot/slaves/slave_ardbeg1/50-SDK/opencv/modules/imgproc/src/filter.cpp:182: error: (-215) 0 <= anchor.x && anchor.x < ksize.width && 0 <= anchor.y && anchor.y < ksize.height in function void cv::FilterEngine::init(const cv::Ptr<cv::BaseFilter>&, const cv::Ptr<cv::BaseRowFilter>&, const cv::Ptr<cv::BaseColumnFilter>&, int, int, int, int, int, const Scalar&)
This means that the anchor point is out of bounds, but I have looked up that the (0,0) point for open CV is the upper left point so I don't think it should be going out of bounds.
Also ideally I would like to do a gaussian blur (instead of just blur) in the region, but I can't figure out how to bound that in the rectangle either: it always blurs the whole image.
Link to ImgProc docs. Any help is greatly appreciated!