Thursday 15 March 2012

java - How to blur a rectagle with OpenCv -



java - How to blur a rectagle with OpenCv -

is there way blur mat object in opencv (for android) blur contained within rect object? doing face blurring application , have tried this:

mat mat = ...; // initialized 480*640 ... mat blurred = new mat(); (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 comment out imgproc.blur part works correctly drawing rectagle around face. however, when run line next in 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 anchor point out of bounds, have looked the (0,0) point open cv upper left point don't think should going out of bounds.

also ideally gaussian blur (instead of blur) in region, can't figure out how bound in rectangle either: blurs whole image.

link imgproc docs. help appreciated!

ok figured out how it:

mat mask = blurred.submat(rect); imgproc.gaussianblur(mask, mask, new size(55, 55), 55); // or other processing

then blurred have blurred region. because submat doesn't re-create info in blurred, rather references it, when blur applied blurs parts in blurred referenced mask.

java android opencv image-processing

No comments:

Post a Comment