图像的行过滤
Posted
技术标签:
【中文标题】图像的行过滤【英文标题】:Row filtering of the image 【发布时间】:2019-04-22 07:09:40 【问题描述】:我在写图片的行过滤过程,出现如下错误。
OpenCV(3.4.1) Error: Assertion failed ((unsigned)pt.y < (unsigned)size.p[0]) in cv::Mat::at, file c:\opencv\3.4.1\build\install\include\opencv2\core\mat.inl.hpp, line 1128
我使用 opencv 中包含的 copyMakeBorder 函数为图像添加填充。
int filter_size = 7;
int h = filter_size / 2;
int top, bottom, left, right;
top = bottom = left = right = h;
Scalar value(0, 0, 0);
copyMakeBorder(double_src, rowPaddedImage, 0, 0, left, right, BORDER_CONSTANT, value);
//Row filter
for (int i = 0; i < rowPaddedImage.rows; i++) //For img
for (int j = h; j < rowPaddedImage.cols - h; j++) //For img
b = g = r = 0.0;
for (int l = 0; l < f_size; l++)
colPaddedImage.at<Vec3d>(Point(i + h, j - h))[0] += rowPaddedImage.at<Vec3d>(Point(i, j - h + l))[0] * filter[l];
colPaddedImage.at<Vec3d>(Point(i + h, j - h))[1] += rowPaddedImage.at<Vec3d>(Point(i, j - h + l))[1] * filter[l];
colPaddedImage.at<Vec3d>(Point(i + h, j - h))[2] += rowPaddedImage.at<Vec3d>(Point(i, j - h + l))[2] * filter[l];
//Kernel loop end
预期结果: 想得到行过滤后的图片,和原图一样大小。
实际结果: 我在编译时收到以下错误消息。
OpenCV(3.4.1) Error: Assertion failed ((unsigned)pt.y < (unsigned)size.p[0]) in cv::Mat::at, file c:\opencv\3.4.1\build\install\include\opencv2\core\mat.inl.hpp, line 1128
【问题讨论】:
"colPaddedImage.at我删除了 Point() 并且只写 colPaddedImage.at(i+h, j-h)[0] 并且解决了我的问题。
【讨论】:
以上是关于图像的行过滤的主要内容,如果未能解决你的问题,请参考以下文章