图片的行过滤

时间:2019-04-22 07:09:40

标签: c++ image opencv

我正在编写图像的行过滤过程,并遇到以下错误。

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

1 个答案:

答案 0 :(得分:0)

我删除了Point(),只写了colPaddedImage.at(i + h,j-h)[0],就解决了我的问题。