Where I was wrong in this row filtering code [closed]

asked 2019-04-22 02:47:00 -0600

hua gravatar image

updated 2019-04-22 02:55:53 -0600

LBerger gravatar image

Code :

 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
            }
        }
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by LBerger
close date 2019-04-22 04:38:34.956631

Comments

1

Have you got an error message?

i is for row and j for colum but Point(x,y) means x for column and y for row

LBerger gravatar imageLBerger ( 2019-04-22 02:57:16 -0600 )edit

This is the error message I got. 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

hua gravatar imagehua ( 2019-04-22 03:18:55 -0600 )edit

I remove the Point() and just only write colPaddedImage.at<vec3d>(i+h, j-h)[0] and that solved my problem. Thank you very much. Could you explain to me what is the difference between using Point() function and not?

hua gravatar imagehua ( 2019-04-22 03:29:23 -0600 )edit
1

colPaddedImage.at<vec3d>(i+h, j-h)[0] < = > colPaddedImage.at<vec3d>(Point(j-h, i+h)[0]

.at<type>(row,col) < = > .at<type>(Point(col,row))

LBerger gravatar imageLBerger ( 2019-04-22 04:38:02 -0600 )edit
1

Thank you for your explanation!

hua gravatar imagehua ( 2019-04-22 04:47:46 -0600 )edit