OpenCV过滤图像的一部分 [英] OpenCV filtering part of an image

查看:86
本文介绍了OpenCV过滤图像的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用C ++ openCV api,我想选择性地仅模糊图像中的某些像素.做这个的最好方式是什么?我试图通过子矩阵来实现它,但是还没能使它正常工作.

I'm using the C++ openCV api, and I would like to selectively blur only certain pixels in an image. What is the best way to do this? I was attempting to do it via submatrices, but haven't been able to get it to work.

//5 is the 'radius' i'm blurring (~1/2 kernel width)
cv::Rect srcRect;
srcRect.x = x - 5;
srcRect.y = y - 5;
srcRect.width = 2*5 + 1;
srcRect.height = 2*5 + 1;

cv::Rect dstRect;
dstRect.x = x;
dstRect.y = y;
dstRect.width = 1;
dstRect.height = 1;

cv::Mat src = srcImage(srcRect);
cv::Mat dst = dstImage(dstRect);

cv::blur(src, dst, cv::Size(5,5));

使用上面的代码,没有任何改变.

With the above code, nothing changes.

当我将两个矩形都设置为srcRect时,子图像会模糊,但是整个dst就会模糊,而不仅仅是单个像素.

When i set both of the rectangles to srcRect, the sub images are blurred, but the entire dst is blurred then, instead of just the single pixel.

有什么想法吗?

推荐答案

srcdst的大小必须相同.在您的示例中,dst是恰好一个像素的子区域.

src and dst must be the same size. In your example, dst is a subregion of exactly one pixel.

除了构建矩形的方法之外,您的代码是正确的.

Your code is correct, besides the way you build rectangles.

Rect srcDstRect(7, 7, 100, 100);
cv::Mat src = srcImage(srcDstRect);
cv::Mat dst = dstImage(srcDstRect);

cv::blur(src, dst, cv::Size(5,5));

这篇关于OpenCV过滤图像的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆