在屏幕截图中模糊Rect [英] Blurring a Rect within a screenshot
问题描述
我正在开发一个Android应用,该应用使用背景Service
来以编程方式捕获当前屏幕上所有内容的屏幕截图.我以Bitmap
的形式获得了屏幕截图.
I'm developing an Android app which uses a background Service
to programmatically capture a screenshot of whatever is on the screen currently. I obtain the screenshot as a Bitmap
.
接下来,我成功导入了 OpenCV 进入我的Android项目.
Next, I successfully imported OpenCV into my Android project.
我现在需要做的是对该图像的子集进行模糊处理,即不是对整个图像本身进行模糊处理,而是对图像中的[矩形]区域或子区域进行模糊处理.我有一个 Rect
对象的数组,它们代表我需要的矩形区域截图中模糊不清.
What I need to do now is blur a subset of this image, i.e. not the entire image itself, but a [rectangular] area or sub-region within the image. I have an array of Rect
objects representing the rectangular regions that I need to blur within the screenshot.
我一直在寻找有关使用Java中的OpenCV进行此操作的教程,但没有找到明确的答案. Mat
和 Imgproc
类显然是您感兴趣的类, Mat.submat()
方法,但是我无法找到有关完成此操作的清晰直接的教程.
I've been looking around for a tutorial on doing this with OpenCV in Java, and I haven't found a clear answer. The Mat
and Imgproc
classes are obviously the ones of interest, and there's the Mat.submat()
method, but I've been unable to find a clear, straightforward tutorial on getting this done.
我在Google上搜索了很多,但没有找到完整的示例.我需要在Java运行时中的Java中执行此操作.
I've googled a lot, and none of the examples I've found are complete. I need to do this in Java, within the Android runtime.
我需要的是:
Bitmap
>>>Mat
>>>>>> Rect
>>>Bitmap
具有投资回报率 模糊.
What I need is:
Bitmap
>>>Mat
>>>Imgproc
>>>Rect
>>>Bitmap
with ROI blurred.
这里有经验丰富的OpenCV开发人员,您能向我指出正确的方向吗?这是我唯一要坚持的事情.
Any experienced OpenCV devs out here, can you point me in the right direction? This is the only thing I'm stuck at.
相关:
推荐答案
下面通过注释和示例图像共享实现此任务的C ++代码:
The C++ code to achieve this task is shared below with comments and sample images:
// load an input image
Mat img = imread("C:\\elon_tusk.png");
img :
// extract subimage
Rect roi(113, 87, 100, 50);
Mat subimg = img(roi);
subimg :
// blur the subimage
Mat blurred_subimage;
GaussianBlur(subimg, blurred_subimage, Size(0, 0), 5, 5);
blurred_subimage :
// copy the blurred subimage back to the original image
blurred_subimage.copyTo(img(roi));
img :
相当于Android的版本:
Android equivalent:
Mat img = Imgcodecs.imread("elon_tusk.png");
Rect roi = new Rect(113, 87, 100, 50);
Mat subimage = img.submat(roi).clone();
Imgproc.GaussianBlur(subimg, subimg, new Size(0,0), 5, 5);
subimg.copyTo(img.submat(roi));
这篇关于在屏幕截图中模糊Rect的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!